| View previous topic :: View next topic |
| Author |
Message |
JonnHalzmans
Joined: 14 Apr 2007 Posts: 1 Location: USA
|
Posted: Wed Oct 31, 2007 2:14 pm Post subject: PHP Multiple Select |
|
|
| When I create a HTML multiple select box the return value in PHP is only a single item not an array as I would expect. |
|
| Back to top |
|
 |
SharkZoneDesign
Joined: 17 Mar 2007 Posts: 15 Location: Phoenix, Arizona
|
Posted: Wed Oct 31, 2007 3:08 pm Post subject: Re: PHP Multiple Select |
|
|
| JonnHalzmans wrote: | | When I create a multiple select box the return value in php is only a single item not an array as I would expect. |
In order to get an array back from the multiple select box in PHP, you have to put array brackets at the end of the select box name. If you don’t, PHP will only populate the $_POST entry with the last element selected.
HTML
| Code: |
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<select name="test[]" multiple="multiple">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
<option value="five">five</option>
</select>
<input type="submit" value="Send" />
</form>
|
PHP
| Code: |
<?php
$test=$_POST['test'];
if ($test){
foreach ($test as $t){echo 'You selected ',$t,'<br />';}
}
?>
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|