user3564246
user3564246

Reputation: 125

HTML Mutli Select Not Posting Values Back to PHP

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

Upvotes: 0

Views: 475

Answers (1)

Quentin
Quentin

Reputation: 943649

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.

Upvotes: 1

Related Questions