以 Jquery select2 的形式发布


POST in a form 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>

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

var_dump($_POST['message-from-select']);

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

string 'michael@example.com' (length=19)

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

答案是在 name 属性后包含 [],这与插件关系不大。

<select multiple name="message-from-select[]" id="message-from-select" class="select2">