【问题标题】:POST in a form Jquery select2以 Jquery select2 形式发布
【发布时间】:2014-12-09 20:55:17
【问题描述】:

所以我正在使用 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)

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

【问题讨论】:

    标签: php jquery select post jquery-select2


    【解决方案1】:

    答案是在name属性后面加上[],这个和插件关系不大。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-14
      • 2015-05-11
      • 2017-10-11
      • 2020-05-15
      • 1970-01-01
      • 2020-10-04
      • 2012-12-08
      相关资源
      最近更新 更多