Possible Duplicate:
zendframework 2 inputfilter customize default error message
I'm trying to use Zend\InputFilter\InputFilter to validate the input from a registration form. I have the code below that:
- Validates the email address in the 'email' field; then
- Checks the value in 'email_confirm' matches the one in 'email'.
This works in in all instances other than when the user leaves both fields blank. In that instance the validator for 'email_confirm' returns the error Array ( [isEmpty] => Value is required and can't be empty )
.
How do I customise this error message? I cannot set it using:
'messages' => array(
'isEmpty' => 'Message Here'
),
because that throws an exception saying (quite rightly) that Zend\Validator\Identical does not have a message template for 'isEmpty'. And it's not picking up the messages I've previously set for the 'email' field, otherwise it would be returning 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