Welcome Guest, Not a member yet? Register   Sign In
set_value/set_checkbox not keeping the checkbox checked if the form is reloaded.
#1

[eluser]Brad K Morse[/eluser]
code for creating the checkboxes step_id[] - it needs to have the name step_id[]

Code:
foreach ($steps as $r) {
  $step_checkbox = array(
      'name'            =>    'step_id[]',
        'id'                =>    'step_id_'.$r->SP_STEPS_ID,
        'value'            =>    $r->SP_STEPS_ID
  );

  if($r->SP_STEPS_OBJECTIVE_ID == $objective_id) {
    print '<div class="steps">';
    
        print '<p>'.form_checkbox($step_checkbox, set_value('step_id[]')).'</p>';
        
        print_r($step_checkbox);
        
    print '</div>';
  }
}

Screenshot of what it looks like

I also tried set_checkbox with no luck.

I copied this right from http://ellislab.com/codeigniter/user-gui...elper.html, and it didn't even work.

Code:
&lt;input type="checkbox" name="mycheck" value="1" &lt;?php echo set_checkbox('mycheck', '1'); ?&gt; /&gt;

The other fields in the form retain the data, but not the step_id[] checkbox, any help is appreciated.
#2

[eluser]rossmurphy[/eluser]
I believe the third parameter of form_checkbox indicated is checked or not. It looks like you are passing in the second parameter which is the value. Try passing in TRUE/FALSE for the third param.
#3

[eluser]Brad K Morse[/eluser]
Tried that with no luck, for both set_value and set_checkbox.
#4

[eluser]rossmurphy[/eluser]
Sorry maybe I was not clear:

Code:
print '<p>'.form_checkbox($step_checkbox, set_value('step_id[]'), TRUE).'</p>';
#5

[eluser]Brad K Morse[/eluser]
that automatically checks every single checkbox, I need them to be unchecked by default, then retain the status of them after being submitted, so set_checkbox and set_value are not working correctly.
#6

[eluser]rossmurphy[/eluser]
So you could check the value and then pass in TRUE/FALSE depending on whether they should be checked or not.
#7

[eluser]Brad K Morse[/eluser]
the user will initially check the checkboxes, post the form, the user may of forgotten to fill in another field that is required, so it will display the form again, with the fields populated with the data they filled pre-post. The data for all the other fields (text, select, textarea) retain their data, but not the step_id[] checkboxes
#8

[eluser]rossmurphy[/eluser]
What you have to do is check whether each checkbox was selected previously, then pass in TRUE if it was, this will then display the checkbox as selected.




Theme © iAndrew 2016 - Forum software by © MyBB