ZF-5399: Checkbox validation problem
Description
Validators don't seem to apply to checkboxes
// ACCEPT CONDITIONS
$this->addElement(
'CheckBox',
'contract',
array(
'label' => 'I accept the terms of service',
'style' =>'margin-left:100px;',
'required' => true,
'checkedValue' => '1',
'validators' => array(array('NotEmpty', true)),
)
);
This seems considered valid ; and whatever validator is put in the validation never seems to occur.
Comments
Posted by Mike Willbanks (digitalstruct) on 2009-06-24T22:21:45.000+0000
I cannot reproduce this in the event of a different validator. NotEmpty is by default added when 'required' => true. However, checkbox has '0' or '1' as a value which would be correct since there was indeed a value set. If you would like the NotEmpty validator or required to trigger an error please use uncheckedValue = null as the following will evaludate to false.
To show you how you could utilize InArray to be able to utilize this event as well: