php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46288 form variable for multiple select returns only single value
Submitted: 2008-10-14 03:08 UTC Modified: 2008-11-09 01:00 UTC
Votes:9
Avg. Score:3.7 ± 1.2
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:1 (20.0%)
From: rveetil at google dot com Assigned:
Status: No Feedback Package: Apache2 related
PHP Version: 5.2.6 OS: Windows XP
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-10-14 03:08 UTC] rveetil at google dot com
Description:
------------
My configuration is Window XP/Apache 6.0.14/PHP 5.2.6. Browser tested- IE6, FireFox 3.0, Google Chrome

The multiple select of the form variable always returns a single value in an array (always returns the top one in the list).

Pick options:  Option A 
               Option B 
               Option C 
               Option D  


I've selected Option B, Option C & Option D



Reproduce code:
---------------
<?php
if ($_POST) {
    echo '<pre>';
    echo htmlspecialchars(print_r($_POST, true));
    echo '</pre>';
}

	$test=$_POST['test'];
	if ($test){
	 foreach ($test as $t){echo 'You selected :',$t,'<br />';}
	}
?>
<form method="POST"  action="<?php echo $_SERVER['PHP_SELF']; ?>">
Pick options: 
<select name="test[]" multiple >
<option value="A"> Option A</option>
<option value="B"> Option B</option>
<option value="C"> Option C</option>
<option value="D"> Option D</option>
</select>
<input type="submit" name="submit">
</form>


Expected result:
----------------
Array
(
    [test] => Array
        (
            [0] => B
            [1] => C
            [2] => D
        )

    [submit] => Submit Query
)

You selected :B
You selected :C
You selected :D



Actual result:
--------------
Array
(
    [test] => Array
        (
            [0] => B
        )

    [submit] => Submit Query
)

You selected :B



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-01 21:04 UTC] jani@php.net
This simplified test works fine for me:
<pre>
<?php
var_dump($_POST);
?>
</pre>
<form method="POST"  action="t.php">
<select name="test[]" multiple >
<option value="A"> Option A</option>
<option value="B"> Option B</option>
<option value="C"> Option C</option>
<option value="D"> Option D</option>
</select>
<input type="submit" name="submit">
</form>

Note: I'm using CGI, not the Apache SAPI module.
 [2008-11-09 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 15:01:29 2024 UTC