Welcome Guest, Not a member yet? Register   Sign In
Setting checkboxes to checked Dynamically
#1

[eluser]opel[/eluser]
I have scoured the forum and documents and getting no where with a simple problem.

I am using the form_helper in the following way to set values of "checked" to a checkbox.

Code:
$data = array(
    'name'        => 'user_phone_fax',
    'id'          => 'user_phone_fax',
    'value'       => 'checked',
    'checked'     => FALSE
    );

echo '<p><label for="user_phone_fax">Fax Facilities : </label>&nbsp;'.form_checkbox($data).'</p>';

However if a user makes an error the values are not being kept as checked.

What is the best way or is there another helper that will set the value to checked if it was selected ?

I tried using the checkbox_set function but couldn't get it to work.

Cheers
#2

[eluser]pistolPete[/eluser]
Please have a look at this bug report: http://ellislab.com/forums/viewthread/104294/

Does this solve your problem?
#3

[eluser]opel[/eluser]
No this didn't solve it but thanks for the link. I have tried adjusting the form helper as per a few other posts.

I think I just going to have to do it manually in my controller.

The solution in the bug tracker doesn't work either.
#4

[eluser]jeffpeck[/eluser]
Try setting checked to "false"... in quotes:
Code:
'checked'     => 'false'

And similarly to "true" in quotes to set is as being checked.
Code:
'checked'     => 'true'
#5

[eluser]jeffpeck[/eluser]
You could do it in one line as:
Code:
'checked' =>$checked?'true':'false'




Theme © iAndrew 2016 - Forum software by © MyBB