I am building a ZendFramework application which as a login form asking for an email address and password - it seemed to make sense to validate the email address before hitting the database with the login attempt, as an invalid email would never lead to a valid hit. Zend_Validate_EmailAddress seemed like the right way to go, but I am having an issue with it generating multiple errors (question at the bottom, after the code).
My form currently has the following
//WPMail_Form_Login::init()
$email = $this->addElement('text', 'email', array(
'label'=>'Email',
'required'=>true,
'filters'=>array('stringtrim'),
'validators'=>array(array('emailaddress', true, array(
'messages'=>array(
'emailAddressInvalidHostname'=>'Your email address is invalid',
'emailAddressInvalidFormat'=>'Your email address is invalid',
'...'=>'(repeat for all message templates)'
)
))),
));
In the controller I directly pass the form into the view:
// WPMail_AuthController::loginAction()
$this->view->form = $form;
And in the view, it's directly echo'd:
// views/scripts/auth/login.phtml
<?php echo $this->form ?>
The result is currently something like this:
- Your email address is invalid
- 'asda!!!' does not match the expected structure for a DNS hostname
- 'asda!!!' does not appear to be a valid local network name
What I want want to know is: Is it possible to configure Zend_
Validate_
EmailAddress in such a way that it only produces a single email-invalid error? By 'configure' I mean, without extending the class and overriding the logic with my own.
TIA.