ZF-5325: Zend_Form_Element_Checkbox::isValid() should use isChecked() if required

Issue Type: Improvement Created: 2008-12-19T14:29:37.000+0000 Last Updated: 2009-10-15T09:14:07.000+0000 Status: Resolved Fix version(s): Reporter: Kirk Madera (aredamkrik) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: - ZF-5399



Checking for required on Zend_Form_Element_Checkbox using notEmpty does not make any sense, in my opinion. "Required" for a checkbox should be defined as the fact that the checkbox was checked; Not that the value is not empty. Here is the solution I am currently using in an extended class of my own:

<pre class="highlight">
    class ZendExt_Form_Element_Checkbox extends Zend_Form_Element_Checkbox
        public function isValid($value, $context = null)

            if ($this->isRequired() && !$this->isChecked())
                $translator      = $this->getTranslator();
                return false;
            return parent::isValid($value, $context);


Posted by Mike Willbanks (digitalstruct) on 2009-06-24T22:23:31.000+0000

Please see issue: ZF-5399 for a code example of how to utilize the functionality by setting the default uncheckedValue to null.

Posted by Matthew Weier O'Phinney (matthew) on 2009-10-15T09:13:51.000+0000

Please see Mike's comment above. I'd argue that you wouldn't mark the checkbox as "required", and if you do, you would add a validator for ensuring that the appropriate value is checked.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.