Requiring a checkbox to be ticked in ZendFramework
Zend Framework "documentation" dosn't say much about validating single checkboxes. If you need to do this, say for a terms ang conditions agreement or something, you have to check that the value is greaterthan zero. To do this, add a validator like this:
Show Plain Text
- $e =new Zend_Form_Element_Checkbox('tnc');
And validate your form in the controller as usual
Show Plain Text- if ($form->isValid($request->getPost())) {
Thanks to Rob Knight for adding how to do this in the bug tracker. http://framework.zend.com/issues/browse/ZF-5920
