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?
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">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With