I'm using Symfony 1.4 and having an issue using multiple form validators.
For part of the form, I need to make sure the email address is valid AND unique. Here's the code I'm trying to use this:
$this->validatorSchema['email_address'] = new sfValidatorAnd(
array(
new sfValidatorEmail(),
new sfValidatorPropelUnique(array('model' => 'Users', 'column' => 'email_address')
),
));
As far as I can tell, this SHOULD work. However, when I post the form, I get the following error message
You must pass an array parameter to the clean() method (this validator can only be used as a post validator).
Any ideas or suggestions?
You can only use the unique validator as a post validator
, just like it says. Meaning you can apply it directly to the field - you need to apply it to the schema through mergePostValidator
. Functionally this is going to produce the same result youre looking for - eg. even if the email is valid, if it already exists you will get the validation error, but if both pass then the form will be valid.
$this->validatorSchema['email_address'] = new sfValidatorEmail();
$this->mergePostValidator(new sfValidatorPropelUnique(array('model' => 'Users', 'column' => 'email_address'));