HTML FORM elements that have a multiple select attribute
dreddySep 28 2009 — edited Sep 30 2009I am migrating some web pages from mod_plsql to php based solutions and have run into an ugly issue. Suppose you have an HTML form, with the checkbox defined below, and you select each checkbox before submitting the form, so you want all 3 values!
mod_plsql does a nice job of mapping multiple select form variables to PL/SQL tables that have the same name as the form element. So for example:
<input type="checkbox" value="tyson" name="boxer">
<input type="checkbox" value="rocky" name="boxer">
<input type="checkbox" value="sugarray" name="boxer">
I'm skipping a few details to illustrate the problem, but consider that the form action is pointing to PL/SQL procedure which is accessed via the mod_plsql gateway. The checkbox element will be mapped to a parameter named "boxer", whose datatype is a PL/SQL table of varchar2...essentially an array of varchar2() indexed by a binary integer.
Attempting to migrate the same html form, except now use a PHP script as the form action instead of a PL/SQL procedure and things don't work the same.
PHP will not map the possible multiple values to an array for you. You'll simply get the last value selected.
You have to introduce PHP array syntax into the HTML control name, which is valid from an HTML point of view, but odd. So you need to add [] to the end of control elements name attribute (which is the PHP syntax for declaring an array). So the example becomes:
<input type="checkbox" value="tyson" name="boxer[]">
<input type="checkbox" value="rocky" name="boxer[]">
<input type="checkbox" value="sugarray" name="boxer[]">
This is important to know as it has sort of foiled our attempt at a staged migration away from mod_plsql to PHP as we need to change more than just the FORMS action, we also need to update all the control elements that have the ability to produce multiple selections, which then renders the FORM unusable with the original PL/SQL procedure as square brackets are not valid in a PL/SQL identifier.
PHP calls this the "array from form element feature", but it's hardly a feature given the effort required to make it happen.