http://www.symfony-project.org/cookbook/1_2/en/conditional-validator
class YourForm extends sfForm {
public configure() {
//...
// add a post validator
$this->validatorSchema->setPostValidator(
new sfValidatorCallback(array('callback' => array($this, 'checkPassword')))
);
}
public function checkPassword($validator, $values)
{
if (!empty($values['username']) && $values['password'] != $values['username'])
{
$error = new sfValidatorError($validator, 'Invalid password');
// throw an error bound to the password field
throw new sfValidatorErrorSchema($validator, array('password' => $error));
}
return $values;
}
}