I am trying to handle multiple multi select boxes/dropdown with same name on one page and on one form. They have the same name because these dropdown/boxes are adding dynamically. My question is how to retrieve data of each select box individually. Its showing the result like this:
Array(
[0] => M
[1] => T
[2] => W
)
But I want the result like this
Array
(
[0] => Array(
[0] => M
[2] => T
)
[1] => Array(
[0] => W
)
)
I am trying this code:
<td class="v-align-middle semi-bold sorting_1">
<div class="form-group form-group-default form-group-default-select2 full-width days" id="111">
<label>SELECT DAYS</label>
<select id="dw" name="days[]" class="full-width select2-offscreen" data-init-plugin="select2" multiple="" tabindex="-1">
<option value="M">Monday</option>
<option value="T">Tuesday</option>
<option value="W">Wednesday</option>
<option value="Th">Thursday</option>
<option value="F">Friday</option>
<option value="Sa">Saturday</option>
<option value="Su">Sunday</option>
</select>
</div> <br/>
</td>
<td>
This is the code I am using to clone my table:
$('.add-ins').on('click', function(){
var selfId = $(this).attr('id');
var tId = $(this).parent().parent().find('table').attr('id');
var lastId = $('.timings#'+tId+' tbody tr:visible:last').attr('id');
lastId++;
$('select').select2('destroy'); /* destroy select2 from select tag and then clone it */
var clonerow = $('.timings#'+tId+' tbody tr:visible:last').clone(true, true).attr('id', lastId);
clonerow.appendTo('.timings#'+tId+' tbody');
$('select').select2(); /* enable Select2 on the select elements */
});
PHP Code:
$days = $_POST['days'];
foreach($days as $value){
echo $value;
foreach($value as $week){
echo $week;
}
}
Or simply this:
print_r($days);
Kindly, help me in this regard. If there is any other solution like using different name for each select box then kindly tell me how to post them using php $_POST as I can not figure out how many multiselect boxes will be added by the user.
Your suggestions will be highly appreciated. Thanks in advance.
Kind Regards
HTMLcode so that we can check