Skip to content

Instantly share code, notes, and snippets.

@marfillaster
Created January 15, 2010 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marfillaster/278064 to your computer and use it in GitHub Desktop.
Save marfillaster/278064 to your computer and use it in GitHub Desktop.
<?php
class ChangePasswordForm extends BaseForm
{
public function configure()
{
$this->getWidgetSchema()->setLabel('old', 'Old Password');
$this->getWidgetSchema()->setLabel('new', 'New Password');
$this->getWidgetSchema()->setLabel('repeat', 'Repeat New Password');
$this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'postValidate'))));
$this->mergePostValidator(new sfValidatorSchemaCompare('new', sfValidatorSchemaCompare::EQUAL, 'repeat', array(), array('invalid' => 'The two passwords must be the same.')));
}
public function postValidate($validator, $values)
{
if($values['old'] && !$this->getOption('sf_user')->checkPassword($values['old']))
{
throw new sfValidatorError($validator, 'Old password is incorrect');
}
return $values;
}
public function setup()
{
$this->setWidgets(array(
'old' => new sfWidgetFormInputPassword(),
'new' => new sfWidgetFormInputPassword(),
'repeat' => new sfWidgetFormInputPassword()
));
$this->setValidators(array(
'old' => new sfValidatorString(),
'new' => new sfValidatorString(),
'repeat' => new sfValidatorString(array('required' => false)),
));
$this->widgetSchema->setNameFormat('password[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
parent::setup();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment