views:

1812

answers:

2

I think I'm missing some simple here, but I can't figure it out for the life of me.

I'm using the set_radio() and set_checkbox() methods to return their values if validation fails, like this

<input type="radio" name="gender" value="male" <? if(!isset($thankyou)) { echo set_radio('gender', 'male'); } ?>/>;Male
<br />
<input type="radio" name="gender" value="female" <? if(!isset($thankyou)) { echo set_radio('gender', 'female'); } ?>/>;Female

I also have another array of checkboxes elsewhere which is larger. Everything is working fine, but on default, the second radio button is checked, and for the checkboxes, ALL of them are checked on default.

If I don't have set_radio / set_checkbox , they are not checked by default, which is what I want.

Adding the 3rd parameter to set_radio() ie. set_radio('gender','male',false) doesn't show any difference as well.

Can anyone shed any light on this please?

Thank you very much!

+1  A: 

All I can say is that this kind of approach is working fine for me:

<input type="radio" name="category_visibility" value="1" <?php echo set_radio('category_visibility', '1', TRUE); ?> /> Visible
<input type="radio" name="category_visibility" value="0" <?php echo set_radio('category_visibility', '0', FALSE); ?> /> Hidden

Your problem could be related to form_validation library, try to set rules for those fields (empty if you actually do not need to validate them):

$this->form_validation->set_rules('category_visibility', 'Visibility', '');
Cinnamon
A: 

I found out the problem, thanks to Cinnamon pointing me in the right direction. The problem was the set_rules were only being set in the validate function, therefore when the default form page was loaded, those rules didn't exist yet.

I duplicated the set_rules in the default function that loads the form view, and everything works as supposed to now.

Only now I need to stream line the validation rules, as they are appearing twice, once in the function that loads the view and once in the validation function...

Winterain