I’ve been running into other folks that have been having trouble with symfony 1.1 on Twitter. One common stumbling block is sfValidatorSchemaCompare.
I’m just gonna paste code here, because I’m now a week behind schedule working with symfony 1.1 because I didn’t pad time for having to read a good chunk of the source of symfony 1.1:
<?php $this->validatorSchema->setPostValidator(new sfValidatorAnd(array( new sfValidatorSchemaCompare('email', '==', 'email_confirm', array(), array('invalid' => 'The email adresses must match') ), new sfValidatorSchemaCompare('password', '==', 'password_confirm', array(), array('invalid' => 'The passwords must match') ), ))); ?>
Anyway it’s been cool getting props for posting code like the above. 😀
Good luck!
5 replies on “sfValidatorCompare Is Now sfValidatorSchemaCompare”
The code won’t work as expected in symfony 1.1 (but will in symfony 1.2). Here is a working snippet:
validatorSchema->setPostValidator(new sfValidatorAnd(array(
new sfValidatorSchemaCompare(’email’, sfValidatorSchemaCompare::EQUAL, ’email_confirm’,
array(),
array(‘invalid’ => ‘The email adresses must match’)
),
new sfValidatorSchemaCompare(‘password’, sfValidatorSchemaCompare::EQUAL, ‘password_confirm’,
array(),
array(‘invalid’ => ‘The passwords must match’)
),
)));
?>
Hi Fabien, Thanks for posting this!
[…] sfValidatorCompare Is Now sfValidatorSchemaCompare […]
thank you for your post. I have a problem with this validator but now everything is greet.
greetings from Poland
It looks great when using 2 fields exists in the schema/model, when I use it with custom field it seems dosen’t work.
here is my code.
$this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare(‘password’, sfValidatorSchemaCompare::EQUAL, ‘re_password’,array(),array(‘invalid’ => ‘The passwords must match’)));
where password is defined in the schema & re_password is a custom field.
It always show ‘The passwords must match’ even though when both r equal.