[eluser]Unknown[/eluser]
Hello I have a problem with checkboxes. I have a hidden field check_ctr which counts for the categories that were checked. Now the problem lies if say I haven't checked the g3. On my model it still inserts the g3 which would be the category other than 3k. I know that my loop is wrong but forgive me CI community I am a noob. . .
Thanks.
The code:
Code:
$limiter = $this->input->post('check_ctr');
echo $limiter;
for($i=1; $i<=$limiter; $i++) {
if($i == 1):
$cat = 3;
$ts = $this->input->post('g3');
elseif($i == 2):
$cat = 5;
$ts = $this->input->post('g5');
elseif($i==3):
$cat = 10;
$ts = $this->input->post('g10');
elseif($i==4):
$cat = 21;
$ts = $this->input->post('g21');
else:
$cat = 42;
$ts = $this->input->post('gun42');
endif;
$form_data2 = array(
'eid' => $maxid,
'cat' => $cat,
'date_init' => set_value('date'),
'time_init' => $ts
);
echo $form_data2;
$this->My_model->save_categories($form_data2);
}
<input type="checkbox" class="input_control" value="g3"/> 3
<input type="text" name="g3" class="gunstart" />
<br />
<input type="checkbox" class="input_control" value="g5"/> 5
<input type="text" name="g5" class="gunstart" />
<br />
<input type="checkbox" class="input_control" value="g10"/> 10
<input type="text" name="g10" class="gunstart" />
<br />
<input type="checkbox" class="input_control" value="g21"/> 21
<input type="text" name="g21" class="gunstart"/>
<br />
<input type="checkbox" class="input_control" value="g42"/> 42
<input type="text" name="g42" class="gunstart"/>
<input type="hidden" name="check_ctr" id="check_ctr">