在表单Jquery select2中POST

amb*_*960 5 php jquery post select jquery-select2

所以我使用的是Select2插件,在表单中发布多个选项时遇到问题.我可以选择多个选项,但只能传递一个:

<form>
  <select multiple name="message-from-select" id="message-from-select" class="select2">
      <option value="janedoen@example.com">janedoen@example.com</option>
      <option value="antonius@example.com" selected="selected">antonius@example.com</option>
      <option value="michael@example.com" selected="selected">michael@example.com</option>
      <option value="bayjack@example.com">bayjack@example.com</option>
      <option value="stacy@example.com">stacy@example.com</option>
  </select>
</form>
Run Code Online (Sandbox Code Playgroud)

在我的PHP页面上,当我选择多个选项后var_dump:

var_dump($_POST['message-from-select']);
Run Code Online (Sandbox Code Playgroud)

我只得到一个字符串,即:

string 'michael@example.com' (length=19)
Run Code Online (Sandbox Code Playgroud)

我需要转到隐藏的输入格式吗?

amb*_*960 11

答案是[]在name属性之后包含,这与插件几乎没有关系.

<select multiple name="message-from-select[]" id="message-from-select" class="select2">
Run Code Online (Sandbox Code Playgroud)