Wednesday, April 27, 2011

Can't set checkbox "checked" with FormHelper

I wrote a view that generates a form. One of the fields is defined in
the database as "tinyint(1)" (aka "bool"). FormHelper->input()
correctly renders a checkbox for this field, but does not set it to
checked, even when the value is 1.

<?= $this->Form->input($field, array(
'value' => $equip[$field]
['value'],
));
//pr($equip[$field]);
?>

Here is the output of the above "pr()" call when it's un-commented:

Array
(
[value] => 1
)

I tried to trace through the code, and think that the problem is in
Helper->value(), which always returns null in this case.

Do I have to treat "bool" checkboxes as a special case?

Even this won't initialize the checkbox as checked:

$this->Form->checkbox('Equipment.collect', array(
'checked' => true, //
$equip['collect'],
))

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: