Zend form - why does validation fail?
I have a password field that is required in the form:

    $pwd = $this->CreateElement('password', 'pwd')
            ->setLabel('Change Password')
            ->setRequired(true)
            ->addValidator('StringLength', false, array(6, 16))
            ->addValidator('regex', false, array('pattern' => $allowed_pattern))
            ->addErrorMessages(array(
                'regexNotMatch' => "Only alpha-numeric characters and some punctuation are allowed.",
            ))
            ->addFilter('StringTrim');

But in the case of an EDIT to the form, I don't want to require this field. There I use:

        $form->getElement('pwd')->setRequired(false);

in my controller before passing the form to the view. When I check the properties of this form element, I have _allowEmpty set to 1 and _required set to 0. However when the form is submitted (with empty field) it fails validation on this field and returns the error message for the RexEx validator above.

Any ideas why field fails validation under these circumstances?
Zend form - why does validation fail?
===

I have a password field that is required in the form:

    $pwd = $this->CreateElement('password', 'pwd')
            ->setLabel('Change Password')
            ->setRequired(true)
            ->addValidator('StringLength', false, array(6, 16))
            ->addValidator('regex', false, array('pattern' => $allowed_pattern))
            ->addErrorMessages(array(
                'regexNotMatch' => "Only alpha-numeric characters and some punctuation are allowed.",
            ))
            ->addFilter('StringTrim');

But in the case of an EDIT to the form, I don't want to require this field. There I use:

        $form->getElement('pwd')->setRequired(false);

in my controller before passing the form to the view. When I check the properties of this form element, I have _allowEmpty set to 1 and _required set to 0. However when the form is submitted (with empty field) it fails validation on this field and returns the error message for the RexEx validator above.

Any ideas why field fails validation under these circumstances?