我试图替换此验证器中的默认“必需”消息:
$this->setValidator('email', new sfValidatorAnd(array(
new sfValidatorEmail(array('required' => true, 'trim' => true)),
new sfValidatorString(array('required' => true, 'max_length' => 80)),
new sfValidatorDoctrineUnique(array(
'model' => 'sfGuardUserProfile',
'column' => 'email'
), array(
'invalid' => 'An account with that email address already
exists. If you have forgotten your password, click "cancel", then "Reset
My Password."'))
)));
但我不知道我应该在哪里添加这样的内容:'required'=> “你必须写你的电子邮件”。
有什么想法吗?
Sf 1.4
哈维
答案 0 :(得分:4)
您必须为sfValidatorAnd定义'required'消息:
$form->setValidator('email', new sfValidatorAnd(array(
new sfValidatorEmail(array('required' => true, 'trim' => true)),
new sfValidatorString(array('required' => true, 'max_length' => 80)),
new sfValidatorDoctrineUnique(array(
'model' => 'sfGuardUserProfile',
'column' => 'email'
), array(
'invalid' => 'An account with that email address already exists. If you have forgotten your password, click "cancel", then "Reset My Password."'))
), array(), array('required' => 'E-mail is required')));
sfValidator并执行清理,它负责设置错误消息。
答案 1 :(得分:0)
你应该将它添加到一个array()中,该数组应该是sfValidatorEmail构造函数的第二个参数。
$this->setValidator('email', new sfValidatorAnd(array(
new sfValidatorEmail(array('required' => true, 'trim' => true)),
new sfValidatorString(array('required' => true, 'max_length' => 80)),
new sfValidatorDoctrineUnique(array(
'model' => 'sfGuardUserProfile',
'column' => 'email'
), array(
'invalid' => 'An account with that email address already
exists. If you have forgotten your password, click "cancel", then "Reset
My Password."'))
),array(), array('required' => 'test custom message')));