0

How can I overwrite Zend validation messages in my code below.

$validatee = array(
                        'email' => $email,
                );
        $validator = array(
                    'email' => array(
                                'EmailAddress',
                                'messages' => array('emailAddressInvalidFormat',"Invalid Email Address")
                            )
                    );

        $emailValidator = new Zend_Filter_Input(null, $validator,$validatee);

I tried doing that but the message doesn't change and always output

"no valid email address in the basic format local-part@hostname"

please help!

ruelluna
  • 787
  • 1
  • 11
  • 30
  • Are you sure this error message is thrown by Zend_FIlter_input?? Isnt this thrown and can be set by an instance of Zend_Validate_EmailAddress? – Eswar Rajesh Pinapala Jun 24 '12 at 06:29
  • I'm not using zend forms for this. I am using Zend_Filter_Input to check if email address is available for registration or not. But before I compare it to my database, it must be validated first as an email address. And yup, the error above is generated. – ruelluna Jun 24 '12 at 06:34
  • i posted a fix, try my answer below – Eswar Rajesh Pinapala Jun 24 '12 at 06:57
  • See http://stackoverflow.com/questions/6036024/one-error-message-instead-of-few-for-zend-validator/6041524#6041524 and http://stackoverflow.com/questions/7942674/zend-emailaddress-validation-returning-multiple-errors/7943869#7943869 – David Weinraub Jun 24 '12 at 08:33

1 Answers1

0

Change your $validator to ::

       can you try adding 
$validator = new Zend_Validate_EmailAddress();
$validator->setMessage(
    'A valid email is required',
    Zend_Validate_EmailAddress::INVALID
); 

and then use in Zend_filter_input?
Eswar Rajesh Pinapala
  • 4,841
  • 4
  • 32
  • 40
  • Still not working. My version is 1.11.11. Very weird because I was able to customize the validation for NotEmpty. $validators = array('username' => array( 'NotEmpty', 'messages'=>array('Username field required.') ), 'password' => array( 'NotEmpty', 'messages'=>array('Password field required.') ) ); – ruelluna Jun 24 '12 at 07:33
  • try my edited ans.. Its kinda wierd why setting messages doesnt work!! – Eswar Rajesh Pinapala Jun 24 '12 at 07:51
  • Server error..I think I have to include tha path to Zend_Validate. How can I include it to my controller/action? – ruelluna Jun 24 '12 at 08:26
  • Dont u use Zend_autoregister to autoload classes?? you can do require_once("Zend/Validate/EmailAddress.php"); – Eswar Rajesh Pinapala Jun 24 '12 at 08:34