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

Description

isValid() won't check for disabled Options.

Example Form-Element:


[..]
$elements['method'] = new Zend_Form_Element_Radio('method');
$elements['method']->setRequired(true);
$elements['method']->setMultiOptions(array(
    '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:


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 **/
            }

            $this->addValidator(
                'InArray',
                true,
                array($options)
            );
        }
    }
    return parent::isValid($value, $context);
}

Comments

a workaround for this problem is:


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
    }
}