sfValidatorCompare Is Now sfValidatorSchemaCompare

by barce on August 13, 2008

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!

{ 4 comments… read them below or add one }

fabien August 14, 2008 at 12:10 am

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’)
),
)));

?>

barce August 14, 2008 at 1:27 pm

Hi Fabien, Thanks for posting this!

krzysztof March 18, 2009 at 2:26 am

thank you for your post. I have a problem with this validator but now everything is greet.

greetings from Poland

shamsh December 20, 2010 at 12:16 am

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.

Leave a Comment

{ 1 trackback }

Previous post:

Next post: