ZF-12345: Zend_Form_Element_Multi doesn't check for disabled options in isValid()

Issue Type: Bug Created: 2012-07-24T08:31:48.000+0000 Last Updated: 2012-07-24T09:21:08.000+0000 Status: Open Fix version(s): Reporter: Joachim Schwarm (uzed_creative) Assignee: Christian Albrecht (alab) Tags: - Zend_Form

Related issues: Attachments:


isValid() won't check for disabled Options.

Example Form-Element:

<pre class="highlight">
$elements['method'] = new Zend_Form_Element_Radio('method');
    'creditcard' => 'pay per creditcard',
    'paypal'     => 'pay per paypal',
    'invoice'    => 'pay per invoice',
$elements['method']->setAttrib('disable', array('invoice'));
$elements['method']->addErrorMessage('please choose a payment method');

isValid() of Zend_Form_Element_Multi:

<pre class="highlight">
public function isValid($value, $context = null)
    if ($this->registerInArrayValidator()) {
        if (!$this->getValidator('InArray')) {
            $multiOptions = $this->getMultiOptions();
            $options      = array();

            foreach ($multiOptions as $opt_value => $opt_label) {
                // optgroup instead of option label
                if (is_array($opt_label)) {
                    $options = array_merge($options, array_keys($opt_label));
                else {
                    $options[] = $opt_value;
/** unset disabled options here **/

    return parent::isValid($value, $context);


Posted by Joachim Schwarm (uzed_creative) on 2012-07-24T09:21:08.000+0000

a workaround for this problem is:

<pre class="highlight">
if ( $form->isValid($this->_getAllParams()) ) {
    if ( in_array($form->getValue('method'), $form->getElement('method')->disable) ) {
        $form->getElement('method')->addErrorMessage('this method is disabled');
    } else {
        // proceed

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.