To show custom message in Symfony forms?
Want to show a custom message in form's error list, i开发者_如何学JAVAf 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.
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
精彩评论