POST in form of jquery select2

So, I am using the Select2 plugin, and I am having trouble submitting multiple options on the form. I can choose several options, but I can only go through:

<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> 

In my PHP page, when I var_dump after selecting several options:

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

I get only one line, for example:

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

Do I need to switch to a hidden input format?

+6
source share
1 answer

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"> 
+12
source

Source: https://habr.com/ru/post/979361/


All Articles