开发者

symfony 1.4: trying to replace the default 'Required' message

开发者 https://www.devze.com 2023-01-13 15:41 出处:网络
im trying to replace the default \'Required\' message in this validator: $this->set开发者_Python百科Validator(\'email\', new sfValidatorAnd(array(

im trying to replace the default 'Required' message in this validator:

 $this->set开发者_Python百科Validator('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."'))
 )));

but i don't know where should i add something like this: 'required' => 'You must write your e-mail').

Any idea?

Sf 1.4

Javi


You have to define 'required' message for sfValidatorAnd:

$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')));

sfValidatorAnd performs cleaning and it's responsible for setting error messages.


you should add it in an array(), which should be second parameter of the sfValidatorEmail constructor.

 $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')));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号