Question

I have a select box in a html form that does not post values back to php.

<select multiple='multiple' name='mydropdown'>
    <option value='1'>1</option>
    <option value='2'>2</option>
    <option value='3'>3</option>
</select>

in PHP if I have a look at the $_REQUEST it returns a single value for the LAST selected value in the select box.

What do I need to change or edit in order to get a array or list of selected items posted back so that I can handle the result in PHP?

I would like to transform the select into a JQuery multi select box so if your answer could apply to JQuery select boxes aswell I would appreciate it

Was it helpful?

Solution

PHP requires that form control names end in [] if you are getting multiple values from the same name.

<select multiple='multiple' name='mydropdown[]'>

It doesn't matter if the reason for getting multiple values is multiple form controls with the same name, or a single select multiple element.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top