Lauren
Lauren

Reputation: 71

Adding a form field that is not in the schema to Doctrine form Symfony 1.4

I have an image upload form and at the bottom, I'd like to have a checkbox that the user must check before submitting the form, certifying that they have the right to distribute the photo. I've tried adding it as a Widget in the Form class, but it is not displaying. What is the best way to accomplish this?

Upvotes: 4

Views: 2906

Answers (2)

Tom
Tom

Reputation: 30698

For validation, you can add this to your form class to allow fields outside the model:

$this->validatorSchema->setOption('allow_extra_fields', true);
$this->validatorSchema->setOption('filter_extra_fields', false); // true or false

Other than that, just adding the widget in the standard way should work fine.

Upvotes: 7

K4emic
K4emic

Reputation: 419

Adding a new widget to your form should be the right way.

class ImageForm extends BaseImageForm
{
  public function configure()
  {

    $this->widgetSchema['copyright'] = new sfWidgetFormInputCheckbox();
  }
}

For conditional validation, check this cookbook page should still be valid.

Upvotes: 1

Related Questions