In the code below I have created a Form_Element for an email address and
setRequired(true).

I added the EmailAddress Validator.

Goal 1: Instead of having the 5 or 6 default validation error messages
possibily displayed I would like simply to say 'Your email address is
invalid' when an invalid email address is entered.

Goal 2: If the field is left blank. I would like 'This field is required' or
similar to be displayed.

I used setErrorMessages on the form element for the invalid message, however
when the field is left blank, the invalid message shows when I would like a
'field required' message to show.

I tried setting different keys in the ErrorMessages array, but can not get
anything to work. What can I do?

$emailValidator = new Zend_Validate_EmailAddress(
            Zend_Validate_Hostname::ALLOW_DNS,
            true);

$emailInput = new Zend_Form_Element_Text('email');
$emailInput->setRequired(true)
                    ->setErrorMessages(array(
                            'Your email address is invalid'
                     ));
$emailInput->addValidator($emailValidator)

Reply via email to