Home >Backend Development >PHP Tutorial >How to get the input data of multiple select in the form
How to get the input data of multiple select in the form
The multiple select element supports selecting multiple options. How to get the multiple selected values?
<pre name="code" class="html"><select multiple="multiple" name="states"> <option value="1">Alabama</option> <option value="2">Alaska</option> <option value="3">California</option> <option value="4">Texas</option> </select>
If the name attribute of select is written in the above form, the value submitted by the form will be the last option selected.
{ "states" : "3" }
should be written as
<select multiple="multiple" name="states[]"> <option value="1">Alabama</option> <option value="2">Alaska</option> <option value="3">California</option> <option value="4">Texas</option> </select>
Form data
{ "states" : [ "2", "3" ] }
The above is how to get the input data of multiple select in the form. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!