[eluser]Unknown[/eluser]
Hi,
I am using checkbox array in my form. When I post my form using ajax I get proper values in a array for check boxes selected values, but when I use native form submission using post method, I get strange values for the same check boxes in a array. Here is the code.
HTML code in my view
Code:
<input type='checkbox' id="monday" name='lp_weekdays[]' value='1' <?= set_checkbox('lp_weekdays[]', '1') ?> required><label for="monday">Monday</label>
<input type='checkbox' id="tuesday" name='lp_weekdays[]' value='2' <?= set_checkbox('lp_weekdays[]', '2') ?>><label for="tuesday">Tuesday</label>
<input type='checkbox' id="wednesday" name='lp_weekdays[]' value='3' <?= set_checkbox('lp_weekdays[]', '3') ?>><label for="wednesday">Wednesday</label>
<input type='checkbox' id="thursday" name='lp_weekdays[]' value='4' <?= set_checkbox('lp_weekdays[]', '4') ?>><label for="thursday">Thursday</label>
<input type='checkbox' id="friday" name='lp_weekdays[]' value='5' <?= set_checkbox('lp_weekdays[]', '5') ?>><label for="friday">Friday</label>
<input type='checkbox' id="saturday" name='lp_weekdays[]' value='6' <?= set_checkbox('lp_weekdays[]', '6') ?>><label for="saturday">Saturday</label>
<input type='checkbox' id="sunday" name='lp_weekdays[]' value='7' <?= set_checkbox('lp_weekdays[]', '7') ?>><label for="sunday">Sunday</label>
Inside my controller
Code:
$this->form_validation->set_rules('lp_weekdays[]', 'Lesson Days', 'required|trim|xss_clean');
Code:
$weekdays = $this->input->post('lp_weekdays');
Say I selected Monday, Wednesday and Friday.
Using Ajax I get $weekdays = array(0 => 1, 1 => 3, 2 => 5)
Using Native submit, I get $weekdays = array( 0 =>[1,2], 1 => [1,2], 2 => [1, 3, 5], 3 => [4,5] )
Any Idea why is it happening?
Vibhu