Hi,

bparise wrote:
But, this doesn't work. Zend_Form::isErrors() doesn't dynamically loop
through elements to get errors (which means the form doesn't get
notification of us adding an error the 'email' element).  Plus, if you call
parent::isValid($data) after we set the email error, they are reset since
Element::isValid() resets the errors.

So, again, what is the best way to handle this situation?
I have previously implemented something like this as follows:

function isValid($data) {
  $ret = parent::isValid($data);
  if( /* insert complex validation logic here */ ) {
     $this->getElement('...')->addError('...');
     $ret = false;
  }
  return $ret;
}

This works fine. Since you already know an element actually *has* an error (you just added it) you do not need to call isErrors(), you already know the validation to have failed. Simply returning false would suffice.

Nevertheless, I'd go with Matthew. Implementing your own validator is the better (reusable, detached, etc) solution.


Gerard

Reply via email to