Tags

class registerForm extends sfGuardUserForm
{
	public function configure()
	{

            sfValidatorBase::setRequiredMessage($I18N->__('A value is required.'));
            sfValidatorBase::setInvalidMessage($I18N->__('This value is invalid.'));

            $this->validatorSchema['password'] = new sfValidatorString(array('required' => true));
            $this->validatorSchema['password_again'] = new sfValidatorString(array('required'=>true, 'max_length'=>'50'), array('invalid' => $I18N->__('Please enter a password or make sure both passwords are the same.'), 'required' => $I18N->__('Please enter a password or make sure both passwords are the same.')));

            $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('password', '==', 'password_again', array(), array('invalid' => $I18N->__('Please enter a password or make sure both passwords are the same.'))));

            $this->validatorSchema['name'] = new sfValidatorString(array('required' => true));
            $this->validatorSchema['surname'] = new sfValidatorString(array('required' => true));

	    $this->widgetSchema['name'] = new sfWidgetFormInput();
	    $this->widgetSchema['surname'] = new sfWidgetFormInput();
	
            $this->validatorSchema['name'] = new sfValidatorCallback(array('callback' => array($this, 'checkNames')));
	    $this->validatorSchema->setPostValidator(
				new sfValidatorCallback(
					array('callback'=> array($this, 'checkNames'))
				)
		);

	}

	public function checkNames($validator, $values) {
		if (empty($values['name']) || empty($values['surname'])) {
			$error = 'Firstname/Lastname is required.';
			throw new sfValidatorErrorSchema($validator, array('name' => new sfValidatorError($validator, $error)));
		}

		return $values;  

	}	

}
Advertisements