我正在尝试更改zfcuser寄存器表单的验证消息。我尝试使用bootstrap.php中的以下代码来更改消息:
$filter->get('email')->setErrorMessage('Email address has been used', \ZfcUser\Validator\AbstractRecord::ERROR_RECORD_FOUND);
但是,这行代码更改了我的所有电子邮件无效消息,但我想要实现的是针对不同错误的不同验证消息。
例如:
Email exist => 'Email address has been used'
Invalid format => 'Email not valid'
Not input => 'Please input your email'
任何人都可以与我分享以实现这一目标吗?
答案 0 :(得分:0)
试试这个。也许它很难看,但它似乎应该有用
$filter = $form->getInputFilter();
$validators = $filter->get('email')->getValidatorChain()->getValidators();
foreach ($validators as $validator) {
if ($validator['instance'] instanceof \ZfcUser\Validator\AbstractRecord) {
$validator['instance']->setOptions(array(
'messageTemplates' => array(
'recordFound' => 'Email address has been used',
),
));
}
}