I am using multiple select2 in one of the forms. After submitting a form, in the backend, only the single selected value is fetched whereas multiple options are selected.
HTML
<form id="test" method="POST">
<select name="dps_days_to[NL]" class="dokan-form-control dps_days_selection" required multiple="multiple">
<option></option>
<option value="0">Sunday</option>
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thurday</option>
</select>
</form>
JS
jQuery(document).ready(function( $ ){
jQuery('.dps_days_selection').select2({
placeholder: "Please select a day"
});
});
PHP
var_dump($_POST['dps_days_to']);
RESULT
Array
(
[0] => 1
)
For example: if Sunday & Monday are selected from available options in select2 multiple dropdown, only the value of options Monday is returned (i.e, 1)
Please, can someone help me?
@Himani
If you want to get data as per name dps_days_to[NL], you can make changes as per below.
Declare [NL] as Array[] i.e. dps_days_to[NL][] , so it can store multiple values.
If [NL] is fixed everytime, then this works.
<select name="dps_days_to[NL][]" class="dokan-form-control dps_days_selection" required multiple="multiple">
RESULT
[dps_days_to] => Array
(
[NL] => Array
(
[0] => 1
[1] => 2
)
)
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