The correct class constant is NOT_SAME
, try using that instead
\Zend\Validator\Identical::NOT_SAME => 'The password is mis matched'
https://github.com/zendframework/zf2/blob/master/library/Zend/Validator/Identical.php#L21
题
How to get a custom error message at passwords (password and confirm_password) miss matched failure in Zend framwork 2 (ZF2)?
I am using following code:
$this->add(array(
'name' => 'password',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 8,
'max' => 15,
'messages' => array(
'stringLengthTooShort' => 'Please enter password minimum 8 character!',
'stringLengthTooLong' => 'Please enter password maximum 15 character!',
)
),
),
),
));
//Confirm Password validation
$this->add(array(
'name' => 'confirm_password',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 8,
'max' => 15,
'messages' => array(
'stringLengthTooShort' => 'Please enter password minimum 8 character!',
'stringLengthTooLong' => 'Please enter password maximum 15 character!',
)
),
),
array(
'name' => 'identical',
'options' => array(
'token' => 'password',
'messages' => array(
\Zend\Validator\identical::NOT_EQUAL => 'The password is mis matched'
)
)
),
),
));
I am using a token for confirm passwords and want to show custom message if token fail. so i use following code to show custom message:
\Zend\Validator\identical::NOT_EQUAL => 'The password is mis matched'
But i am getting following error:
Fatal error: Undefined class constant 'NOT_EQUAL' in C:\wamp\www\zend\module\*******
解决方案
The correct class constant is NOT_SAME
, try using that instead
\Zend\Validator\Identical::NOT_SAME => 'The password is mis matched'
https://github.com/zendframework/zf2/blob/master/library/Zend/Validator/Identical.php#L21