Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST in a form Jquery select2

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?

like image 350
ambe5960 Avatar asked Dec 09 '14 20:12

ambe5960


1 Answers

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">
like image 116
ambe5960 Avatar answered Sep 28 '22 20:09

ambe5960