public function configure() { $this->setWidgets(array('5' => new sfWidgetFormInputText())); $this->setValidators(array('5' => new sfValidatorString())); $this->widgetSchema->setLabels(array('5' => 'label' . $this->getOption('salt'))); $this->widgetSchema->setHelps(array('5' => 'help' . $this->getOption('salt'))); } } sfForm::disableCSRFProtection(); // __construct() $t->diag('__construct'); $f = new FormTest(); $t->ok($f->getValidatorSchema() instanceof sfValidatorSchema, '__construct() creates an empty validator schema'); $t->ok($f->getWidgetSchema() instanceof sfWidgetFormSchema, '__construct() creates an empty widget form schema'); $f = new sfForm(array('first_name' => 'Fabien')); $t->is($f->getDefaults(), array('first_name' => 'Fabien'), '__construct() can take an array of default values as its first argument'); $f = new FormTest(array(), array(), 'secret'); $v = $f->getValidatorSchema(); $t->ok($f->isCSRFProtected(), '__construct() takes a CSRF secret as its second argument'); $t->is($v[sfForm::getCSRFFieldName()]->getOption('token'), '*secret*', '__construct() takes a CSRF secret as its second argument'); sfForm::enableCSRFProtection(); $f = new FormTest(array(), array(), false); $t->ok(!$f->isCSRFProtected(), '__construct() can disable the CSRF protection by passing false as the second argument'); $f = new FormTest(); $t->ok($f->isCSRFProtected(), '__construct() uses CSRF protection if null is passed as the second argument and it\'s enabled globally'); // ->getOption() ->setOption() ->getOptions() $t->diag('->getOption() ->setOption()'); $f = new FormTest(array(), array('foo' => 'bar')); $t->is($f->getOption('foo'), 'bar', '__construct takes an option array as its second argument'); $f->setOption('bar', 'foo'); $t->is($f->getOption('bar'), 'foo', '->setOption() changes the value of an option');
/** * Embeds a sfForm into the current form. * * @param string $name The field name * @param sfForm $form A sfForm instance * @param string $decorator A HTML decorator for the embedded form */ public function embedForm($name, sfForm $form, $decorator = null) { $name = (string) $name; if (true === $this->isBound() || true === $form->isBound()) { throw new LogicException('A bound form cannot be embedded'); } unset($form[self::$CSRFFieldName]); $this->embeddedForms[$name] = $form; $widgetSchema = $form->getWidgetSchema(); $this->setDefault($name, $form->getDefaults()); $decorator = null === $decorator ? $widgetSchema->getFormFormatter()->getDecoratorFormat() : $decorator; $this->widgetSchema[$name] = new sfWidgetFormSchemaDecorator($widgetSchema, $decorator); $this->validatorSchema[$name] = new sfValidatorPass(); // keep widgetSchema synchronized $form->setWidgetSchema($this->widgetSchema[$name]->getWidget()); $this->resetFormFields(); }