开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜