ZF-10690: Zend_Validate_EmailAddress: Allow setMessage to set all messages


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


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.

Fixed with GH-83

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.

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…

Attaching patch.

Committed backported patch to 1.12 in r24848. Thanks, Martin!