php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #1587 CGI POST and GET multi-valued names are handled very poorly.
Submitted: 1999-06-22 20:09 UTC Modified: 1999-11-26 14:04 UTC
From: chris at claimlynx dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 3.0.9 OS: FreeBSD
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chris at claimlynx dot com
New email:
PHP Version: OS:

 

 [1999-06-22 20:09 UTC] chris at claimlynx dot com
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-11-26 14:04 UTC] rasmus at cvs dot php dot net
I really don't see any compelling reason to change this behaviour.  
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Jun 16 02:00:01 2026 UTC