HTML Mutli Select Not Posting Values Back to PHP

2019-03-06 11:09发布

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

1条回答
做个烂人
2楼-- · 2019-03-06 12:07

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.

查看更多
登录 后发表回答