views:

33

answers:

1

What is the use of hidden fields for checkbox in cakePHP??

+4  A: 

It's so there's always some data submitted for the field, even if the box is not checked. This becomes especially important if you're using the SecurityComponent. You can turn it off by setting 'hiddenField' => false as an option.

deceze
It was a real aha! moment for me when I realized why cake did this. It just makes your backend code much nicer, when you can check for == 0 rather than if the variable is set, then checking its value.
Travis Leleu
but it gets problem when i try save with HABTM relations :(it also inserts the data with value 0
RSK
@RSK In that case you can either `array_filter` the values in your controller, or use the `'hiddenField' => false`.
deceze
@deceze: done `'hiddenField' => false` :)
RSK