Bug #1587: CGI POST and GET multi-valued names are handled very poorly.
| From: | chris at claimlynx dot com | Date: | Wed, 23 Jun 1999 00:09:25 +0000 |
| Subject: | Bug #1587: CGI POST and GET multi-valued names are handled very poorly. | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-7446@lists.php.net to get a copy of this message | ||
From: chris@claimlynx.com
Operating system: FreeBSD
PHP version: 3.0.9
PHP Bug Type: Feature/Change Request
Bug description: CGI POST and GET multi-valued names are handled very poorly.
There's a work-around for this problem described in the FAQ. The problem is, it is just that,
a work-around.
It makes what should have been a completely portable HTML FORM no longer portable. One should not
have to change the name of SELECT MULTIPLE and multiple CHECKBOX inputs in a FORM to include
PHP's
needed square brackets to trick PHP into not losing all but the last value sent. And then remove
them, if future
development requires that the form's action is to call something other than a PHP script.
Here's the crux of the issue. No correctly designed CGI module should be throwing away data,
and that's
exactly what PHP3 does by default. With all the very clever and complicated code involved in making
PHP3
work, surely it is not beyond the designers and programmers to come up with a "gee, if
we've seen this
CGI variable once before, do something intelligent" instead of the simple-minded "got a
token, assign
the value seen right here" method which seems to have been used.
Make it an array, a list, a comma-delimited string -- anything but toss the previous values.
Here's the FAQ page in case it's not immediately obvious what I'm talking about:
5.9 How do I get all the results from a SELECT MULTIPLE HTML tag?
The SELECT MULTIPLE tag in an HTML construct allows users to select
multiple items from a list. These items are then passed to the
action handler for the form. The problem is that they are all passed
with the same widget name. ie.
<SELECT NAME="var" MULTIPLE>
Each selected option will arrive at the action handler as:
var=option1
var=option2
var=option3
Each option will overwrite the contents of the previous $var
variable. The solution is to use PHP's non-indexed array feature.
The following should be used:
<SELECT NAME="var[]" MULTIPLE>
This tells PHP to treat var as an array and each assignment of a
value to var[] adds an item to the array. The first item becomes
$var[0], the next $var[1], etc. The count() function can be used
to determine how many options were selected, and the sort() function
can be used to sort the option array if necessary.