开发者

Don't show column name when validator returns an error

I have the following code:

$this->form->s开发者_开发知识库etValidators(array(
    'email'   => new sfValidatorAnd(
        array(
            new sfValidatorEmail(array(), array(
                'invalid' => 'Enter a valid email address.',)),
            new sfValidatorDoctrineUnique(array(
                'model'=>'Users',
                'column'=>'email',
                ), array(
                'invalid' => 'This email is already being used.',
                )),
        ),
        array(),
        array(
                'required' => 'Required',
        )
    ),
//...

and when the email is not unique, it returns the following error: email: This email is already being used. But I don't want that email: in front of the message.

Is there a way I can stop showing the column name?

Can I get some help?


This is a special of sfValidatorDoctrineUnique, so it may be necessary to test uniqueness over more than one column.

You have to override the doClean() method to prevent this line (at the end) :

throw new sfValidatorErrorSchema($this, array($columns[0] => $error));    

Further informations :

  • sfValidatorDoctrineUnique source
  • http://oldforum.symfony-project.org/index.php/m/91044/


You can pass throw_global_error option to the sfValidatorDoctrineUnique, in order to throw your error and don't display the <column>::

  new sfValidatorDoctrineUnique(
    array('throw_global_error' => true, 'column' => 'email'),
    array('invalid' => 'Custom message')
  )

Hope it's helpful.

Best regard.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜