Harish Kurup
Harish Kurup

Reputation: 7505

To show custom message in Symfony forms?

Want to show a custom message in form's error list, if the two fields did not match. the from is as follows, 'old_password' =>'Old Password*', 'new_password' =>'New Password*', 'confirm_password' =>'Confirm Password*', I want that the old password should match the value from the database, the value in new password and confirm password should also match. please help me.

Upvotes: 1

Views: 934

Answers (1)

danii
danii

Reputation: 5693

In Symfony 1.1 and later, to compare if the two form fields match you need to set up a post validator, like:

$this->validatorSchema->setPostValidator(
  new sfValidatorSchemaCompare(
    'new_password', 
    sfValidatorSchemaCompare::EQUAL, 
    'confirm_password',
    array(),
    array('invalid' => 'Your custom error message here!!')
  )
);

Try reading Symfony forms in Action, it should solve most of your problems about form creation and validation within the Symfony framework

Upvotes: 3

Related Questions