Welcome Guest, Not a member yet? Register   Sign In
$this->input->post returning strage values for checkbox array
#1

[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:
&lt;input type='checkbox' id="monday" name='lp_weekdays[]' value='1' &lt;?= set_checkbox('lp_weekdays[]', '1') ?&gt; required&gt;&lt;label for="monday">Monday</label>
&lt;input type='checkbox' id="tuesday" name='lp_weekdays[]' value='2' &lt;?= set_checkbox('lp_weekdays[]', '2') ?&gt;&gt;&lt;label for="tuesday">Tuesday</label>
&lt;input type='checkbox' id="wednesday" name='lp_weekdays[]' value='3' &lt;?= set_checkbox('lp_weekdays[]', '3') ?&gt;&gt;&lt;label for="wednesday">Wednesday</label>
&lt;input type='checkbox' id="thursday" name='lp_weekdays[]' value='4' &lt;?= set_checkbox('lp_weekdays[]', '4') ?&gt;&gt;&lt;label for="thursday">Thursday</label>
&lt;input type='checkbox' id="friday" name='lp_weekdays[]' value='5' &lt;?= set_checkbox('lp_weekdays[]', '5') ?&gt;&gt;&lt;label for="friday">Friday</label>
&lt;input type='checkbox' id="saturday" name='lp_weekdays[]' value='6' &lt;?= set_checkbox('lp_weekdays[]', '6') ?&gt;&gt;&lt;label for="saturday">Saturday</label>
&lt;input type='checkbox' id="sunday" name='lp_weekdays[]' value='7' &lt;?= set_checkbox('lp_weekdays[]', '7') ?&gt;&gt;&lt;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




Theme © iAndrew 2016 - Forum software by © MyBB