php - Making zend EmailAddress form validator return only one custom error message -
i'm creating email form element (inside zend form):
//create e-mail element $email = $this->createelement('text', 'username') ->setlabel('e-mail:') ->setrequired(true) ->addfilters(array('stringtrim', 'stringtolower')) ->addvalidator('emailaddress', false, array( 'messages' => array( zend_validate_emailaddress::invalid => 'dit e-mail adres ongeldig.', ) )); //add element $this->addelement($email);
now, when invalid e-mail entered quite lot of messages appear:
'#' no valid hostname email address '@#$@#' '#' not match expected structure dns hostname '#' not appear valid local network name '@#$' can not matched against dot-atom format '@#$' can not matched against quoted-string format '@#$' no valid local part email address '@#$@#'
i wonder, possible make emit error message provided me, such 'please enter valid e-mail address.'?
the easiest way use adderrormessage()
set single custom message errors.
in example can add code , call fluently, or add line
$email->adderrormessage('dit e-mail adres ongeldig.');
you should change second parameter addvalidator below, once validation has failed other conditions aren't checked.
->addvalidator('emailaddress', true)
it explained in reference guide not well. name adderrormessage
doesn't imply override default messages, there are.
Comments
Post a Comment