sfValidatorCompare Is Now sfValidatorSchemaCompare

Written by

in

,

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!

Comments

5 responses to “sfValidatorCompare Is Now sfValidatorSchemaCompare”

  1. fabien Avatar

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

    ?>

  2. barce Avatar
    barce

    Hi Fabien, Thanks for posting this!

  3. […] sfValidatorCompare Is Now sfValidatorSchemaCompare […]

  4. krzysztof Avatar
    krzysztof

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

    greetings from Poland

  5. shamsh Avatar
    shamsh

    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 Reply

Your email address will not be published. Required fields are marked *