Welcome Guest, Not a member yet? Register   Sign In
For Loop when the first one isn't check still reads the first checkbox
#1

[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);
   }





&lt;input type="checkbox" class="input_control" value="g3"/&gt; 3
&lt;input type="text" name="g3" class="gunstart" /&gt;
<br />
&lt;input type="checkbox" class="input_control" value="g5"/&gt; 5
&lt;input type="text" name="g5" class="gunstart" /&gt;

<br />

&lt;input type="checkbox" class="input_control" value="g10"/&gt; 10
&lt;input type="text" name="g10" class="gunstart" /&gt;

<br />

&lt;input type="checkbox" class="input_control" value="g21"/&gt; 21
&lt;input type="text" name="g21" class="gunstart"/&gt;

<br />

&lt;input type="checkbox" class="input_control" value="g42"/&gt; 42
&lt;input type="text" name="g42" class="gunstart"/&gt;


&lt;input type="hidden" name="check_ctr" id="check_ctr"&gt;




Theme © iAndrew 2016 - Forum software by © MyBB