Tuesday, February 28, 2012

Can't set checkbox value to 0

Hello,

i want to use a checkbox with inverted results: if checked- the value would be 0 and if not- 1, for which i am using the value attributes of both the checkbox and the corresponding hidden field:

$formMarkup = array('verification_needed' = array('label' => __('Don\'t verify'), 'type' => 'checkbox', 'value' => 0, 'hiddenField' => array('value' => 1), 'name' =>'Registration[verification_needed]'));
echo $this->Form->inputs($formMarkup);

However, i can't get the part whith checked = 0 working. The source of the rendered page shows that the value of the checkbox (as well as the value of the hidden field) has the value=1.
If i set any other value to the checkbox- like 555 or "yes" - it gets correctly assigned, but if i try 0- the value is always 1.

Is this behavior normal and how could i set the value to 0?

I use cake 2.1

Best regards,

Boyan

--
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: