setWidgets(array( 'id' => new sfWidgetFormInputHidden(), 'email' => new sfWidgetFormInput(), 'firebug_user' => new wtWidgetFormInputCheatbox(), 'code' => new sfWidgetFormInput(), 'yml' => new sfWidgetFormInput(), )); $this->setValidators(array( 'id' => new sfValidatorPropelChoice(array('model' => 'Application', 'column' => 'id', 'required' => false)), 'email' => new sfValidatorEmail(array('max_length' => 255)), 'firebug_user' => new sfValidatorBoolean(), 'code' => new sfValidatorUrl(array('max_length' => 255)), 'yml' => new sfValidatorString(array('max_length' => 255)), )); $this->widgetSchema->setNameFormat('application[%s]'); $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema); parent::setup(); /* — Holy crap! How did you manage to put the stuff in _this_ class? I mean, it's autogenerated! — This is done with the help of alloys, a powerful system developed internally. Not only it allows to append new methods, but also modify existing code: note the renamed validators in ->setValidators() call. The system is still in beta, but has already been used in a few projects. I'm determined to contribute alloys into Symfony 2.0. */ $this->validatorSchema->setPostValidator( new sfValidatorCallback(array('callback' => array($this, 'postValidate'))) ); } public function getModelName() { return 'Application'; } public function postValidate(sfValidatorCallback $validator, $values) { $existingErrors = $this->errorSchema->getNamedErrors(); $errors = array(); foreach ($this->validatorSchema->getFields() as $name=>$v) { $method = 'validate'.sfInflector::camelize($name); try { $v->clean($values[$name]); } catch (sfValidatorError $e) { continue; } if (method_exists($this, $method)) { if ($error = $this->$method($validator, $values)) { $errors[$name] = $error; } } } if ($errors) { throw new sfValidatorErrorSchema($this->validatorSchema, $errors); } return $values; } public function validateFirebugUser(sfValidatorCallback $validator, $values) { if (empty($values['firebug_user'])) { return new sfValidatorError($validator, 'required'); } } public function validateYml(sfValidatorCallback $validator, $values) { if ($values['yml'] != sfConfig::get('app_knights_phrase')) { return new sfValidatorError($validator, 'invalid'); } } }