1

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 .

2
  • 1
    only the selected items get posted Commented Feb 7, 2011 at 17:33
  • issue was related to another part of the code. Thanks for the answers. Commented Feb 10, 2011 at 14:37

3 Answers 3

1

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]

Sign up to request clarification or add additional context in comments.

Comments

0

You have not included multiple in html code of select.

You should use

<select name="name[]" multiple size"5">

Comments

0

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"> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.