Welcome Guest, Not a member yet? Register   Sign In
How to set default value to unchecked for radio buttons/checkboxes while using set_radio and set_checkbox ?
#1

[eluser]winterain[/eluser]
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

Code:
<input type="radio" name="gender" value="male" <? if(!isset($thankyou)) { echo set_radio('gender', 'male'); } ?>/>Male
<br />
&lt;input type="radio" name="gender" value="female" &lt;? if(!isset($thankyou)) { echo set_radio('gender', 'female'); } ?&gt;/&gt;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!
#2

[eluser]Flemming[/eluser]
I really want to offer a solution here because I see that lots of people have read your question but haven't been able to help! But I can't see anything wrong with your code!

When you say 'on default' ... you're not refreshing the page are you? I mean, you are actually loading the page again by hitting enter at the end of the address bar rather than hitting the refresh button? (as a normal refresh will remember your existing radio and checkbox statuses)

:-|
#3

[eluser]winterain[/eluser]
I found out the problem.

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...
#4

[eluser]Flemming[/eluser]
ahhh glad you got to the bottom of it!

if you need an example of how to streamline things, this may help you (see post #6)

http://ellislab.com/forums/viewthread/135367/




Theme © iAndrew 2016 - Forum software by © MyBB