iBiryukov
iBiryukov

Reputation: 1740

Zend Validate, Display one message per validator

I am validating an email address using zend_validate_email. For example, for email address aa@aa it throws several error messages including very technical describing that DNS mismatch (:S).

I am trying to make it display only 1 message that I want it to (for example: "Please enter a valid email").

Is there any way of doing it elegantly, apart from creating a subclass and overriding the isValid method, clearing out the array of error messages?

Thanks!

Upvotes: 2

Views: 734

Answers (1)

David
David

Reputation: 404

$validator = new Zend_Validate_EmailAddress();
// sets the message for all error types
$validator->setMessage('Please enter a valid email');
// sets the message for the INVALID_SEGMENT error
$validator->setMessage('Something with the part after the @ is wrong', Zend_Validate_EmailAddress::INVALID_SEGMENT);

For a full list of errors and message templates see the Zend_Validate_EmailAddress class

Upvotes: 1

Related Questions