Reputation: 2040
I have , within a foreach , a dropdown:
`<select name="position[]">
<option value="1st">First</option>
<option value="2nd">Second</option>
<option value="3rd">Third</option>
</select>`
I need to be able to get the values from position[]
when the form is posted
I had assumed it was $_POST['position'][0]
, $_POST['position'][1]
etc.
But that doesn't work .
Upvotes: 1
Views: 3823
Reputation: 17169
Try this:
$test=$_POST['position'];
if ($test){
foreach ($test as $t){
echo 'You selected '.$t.'<br />';
}
}
and also in select tag enable multiple selection by:
<select name="position[]" multiple="multiple">
Upvotes: 0
Reputation: 614
Try this:
<?php
foreach($array as $key=>$value){ ?>
<select name="position[<?php echo $key; ?>]">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select>
<?php } ?>
You should then be able to access each select like this:
$_POST['position'][$key]
Upvotes: 1
Reputation: 28755
You have not included multiple
in html code of select.
You should use
<select name="name[]" multiple size"5">
Upvotes: 0