$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')
),
)));
this compare two values from Form.
I would like make compare with own values:
new sfValidatorSchemaCompare('secret_key', '==', '123456',
array(),
array('invalid' => 'The secret key must match')
),
How can i make it?
The
sfValidatorSchemaComparecompares the entered value in two fields (like in your first example).For example: it tests if the
passwordmatches thepassword_confirmvalues. In this case both thepasswordandpassword_confirmhave to be fields in your form (validators to be exact).In your case, you want to check if a
secret_keymatches a predefined value, not another field.And this is a bit strange, by default symfony doesn’t have a validator to check this. But you can easily use the
sfValidatorChoiceto achieve your target:In this case the value entered in
secret_keyis matched against a list of values, which only contains your secret key.And a little “pro-tip” ;-): Add the secret_key to your app.yml, and then just add
sfConfig::get('app_form_secret_key')to test.