I have the next element:
$email = new Zend_Form_Element_Text('email');
$email->setAttribs(array('class' => 'input-text', 'id' => 'email'))
->setLabel($this->view->translate('Email'))
->setValue(null)
->setRequired(true)
->addValidator(new Zend_Validate_EmailAddress())
->setDecorators($emailMessageDecorators);
If there are more than one mistake in the email address, some errors are displaying. Like this:
'fff.fgdf' is no valid hostname for email address 'as@fff.fgdf'
'fff.fgdf' appears to be a DNS hostname but cannot match TLD against known list
'fff.fgdf' appears to be a local network name but local network names are not allowed
How can I set only 1 message? I have tryed setMessage(string), but it shows 3 same errors. Thanks. Sorry for my english. Peace & love)
In the past, I had to make a custom validator for that:
Then called using:
$email->addValidator(new App_Validate_EmailAddressSimpleMessage());If you just want to use the same syntax as usual:
$email->addValidator('EmailAddress');but have it use this validator, then you can change the classname/filename from
EmailAddressSimpleMessageto simplyEmailAddressand register the prefixApp_Validate_with the form/elements.Even better would probably be to allow this class to accept an optional constructor parameter for the message you want, but I was going quick-and-dirty at the time.