ZF-10690: Zend_Validate_EmailAddress: Allow setMessage to set all messages
Description
If you use setMessage without a message key, it's supposed to set all of the message templates to the given message. So When I do
$emailValidator = new Zend_Validate_EmailAddress; $emailValidator->setMessage("Invalid Email Address");
I would expect all error messages to be 'Invalid Email Address', instead my errors look like
[emailAddressInvalidHostname] => 'iasdf' is no valid hostname for email address 'ASDF@iasdf' [hostnameInvalidHostname] => 'iasdf' does not match the expected structure for a DNS hostname [hostnameLocalNameNotAllowed] => 'iasdf' appears to be a local network name but local network names are not allowed
I read through the code, It looks like the setMessage method for Zend_Validate_EmailAddress is overloading the Zend_Validate_Abstract method The abstract method has
foreach($keys as $key) { $this->setMessage($messageString, $key); }
Zend_Validate_EmailAddress does not
When I add the foreach to the email address validator it fixes the problem
Comments
Posted by Ross Ghahremani (rossghahremani) on 2010-11-20T22:08:19.000+0000
I don't think this is a duplicate, from what i can tell, the ticked linked as the duplicate is what caused this problem, the change was made in the abstract, but not in the extended EmailAddress validator. I've already started to not use these messages, because as another person pointed out, they aren't for end user consumption, but it still should work as expected.
Posted by Thomas Weidner (thomas) on 2010-12-18T10:36:17.000+0000
Fixed with GH-83
Posted by Sylvain DIDELOT (neck) on 2012-02-12T14:25:12.000+0000
Despite marked as fixed this is still an issue in 1.11.11 .
Zend_Validate_EmailAddress::setMessage will only set the first message and ignore others if $key is null. This is inconsistent with abstract method.
Posted by Martin Hujer (mhujer) on 2012-05-17T17:17:09.000+0000
Reopening as it is still an issue in upcoming ZF 1.12 (was fixed just in ZF 2) and it should be easy to fix - just manualy merge stuff from https://github.com/zendframework/zf2/…
Posted by Martin Hujer (mhujer) on 2012-05-19T14:30:08.000+0000
Attaching patch.
Posted by Adam Lundrigan (adamlundrigan) on 2012-05-30T12:24:18.000+0000
Committed backported patch to 1.12 in r24848. Thanks, Martin!