How do you check a checkbox in HTML? You add a "checked" attribute and give it some value since there are some parsers which doesn't understand attributes without values (and XHTML doesn't allow it anyway). So for example:
<input type="checkbox" name="chksg" checked="yes" />
Now I've tried the same practice in a Cake view like so:
echo $form->input("chksg", array("type" => "checkbox", "checked" => "yes"))
This failed because Cake can only treat "checked" attributes as booleans. So we must put the above like this below:
echo $form->input("chksg", array("type" => "checkbox", "checked" => true))
This is why I think it would be better to test these attributes with the empty() function (see in the manual) inside Cake, so when it's an empty string or false the checkbox won't be checked, but when it's true or a non-empty string it will be.
Utolsó kommentek