Possible duplicate:
zendframework 2 inputfilter set default error message
I am trying to use Zend \ InputFilter \ InputFilter to validate input from a registration form. I have the code below:
- Confirms the email address in the "email" field; then
- Checks that the value in 'email_confirm' matches the value in 'email'.
This works in all cases, except when the user leaves both fields blank. In this case, the validator for 'email_confirm' returns an error Array ( [isEmpty] => Value is required and can't be empty ) .
How to configure this error message? I can not install it using:
'messages' => array( 'isEmpty' => 'Message Here' ),
because it throws an exception (quite rightly) that Zend \ Validator \ Identical does not have a message template for 'isEmpty'. And it does not pick up the messages that I previously set for the "email" field, otherwise it will return Array ( [isEmpty] => Please enter your email address ) .
$this->add($inputFactory->createInput(array( 'name' => 'email', 'required' => true, 'filters' => array( array('name' => 'StripTags'), array('name' => 'StringTrim'), ), 'validators' => array( array( 'name' =>'NotEmpty', 'options' => array( 'messages' => array( 'isEmpty' => 'Please enter your email address' ), ), ), array( 'name' => 'StringLength', 'options' => array( 'encoding' => 'UTF-8', 'max' => 200, 'messages' => array( 'stringLengthTooLong' => "Email addresses cannot be more than 200 characters" ), ), ), array( 'name' =>'EmailAddress', 'options' => array( 'useMxCheck' => true, ), ), ), ))); $this->add($inputFactory->createInput(array( 'name' => 'email_confirm', 'required' => true, 'filters' => array( array('name' => 'StripTags'), array('name' => 'StringTrim'), ), 'validators' => array( array( 'name' => 'Identical', 'options' => array( 'token' => 'email', 'messages' => array( 'notSame' => "Your email addresses do not match, please try again", ), ), ), ), )));
Thanks Neil