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

PHP中文网
PHP中文网Original
2016-07-28 08:28:181682browse

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)!



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn