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
EmailAddressSimpleMessage
to simplyEmailAddress
and 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.
You using this example:
This is an example(I hope it helps) :
If I recall correctly, you can call setErrorMessages() to set a single error message on the form element, rather than calling setMessages() on each individual validator:
Here is the answer, by using $breakChainOnFailure = true:
Cited: http://framework.zend.com/manual/1.12/en/zend.form.elements.html#zend.form.elements.validators.errors