Will creates nice web-things, builds awesome ideas, and collaborates with other creative types.

Home > Blog > Requiring a checkbox to be ticked in ZendFramework

Requiring a checkbox to be ticked in ZendFramework

by Will on Aug 2nd 2011, 20:59

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
  1. $e =new Zend_Form_Element_Checkbox('tnc');
  2. $e->addValidator('GreaterThan', false, array(0));

And validate your form in the controller as usual

Show Plain Text
  1. 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

Requiring a checkbox to be ticked in ZendFramework Fail zend framework zf

blog comments powered by Disqus