POST in a form Jquery select2
Asked Answered
P

1

9

So I am using the Select2 plugin, and am having trouble posting multiple options in a form. I am able to select multiple options but can only pass one through:

<form>
  <select multiple name="message-from-select" id="message-from-select" class="select2">
      <option value="[email protected]">[email protected]</option>
      <option value="[email protected]" selected="selected">[email protected]</option>
      <option value="[email protected]" selected="selected">[email protected]</option>
      <option value="[email protected]">[email protected]</option>
      <option value="[email protected]">[email protected]</option>
  </select>
</form>

On my PHP page, when I var_dump after selecting multiple options:

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

I only get one string coming through, i.e.:

string '[email protected]' (length=19)

Do I need to go to a hidden input format?

Piragua answered 9/12, 2014 at 20:55 Comment(0)
P
15

The answer is to include [] after the name attribute, which has little to do with the plugin.

<select multiple name="message-from-select[]" id="message-from-select" class="select2">
Piragua answered 9/12, 2014 at 21:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.