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.
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.
精彩评论