Snippet: Symfony Forms - Allowing Extra Fields

Place this line of code in the configure method of a Symfony form to allow the saving of additional fields. This is used when additional information or inputs are needed in the form which are not saved in their own fields in the database. Examples are data which might be serialized into an array and stored in a single field, or when uploading multiple files but only saving one reference or filename.

  // lib/form/MyModelForm.class.php 
  public function configure() {
    $this->validatorSchema->setOption('allow_extra_fields', true);

When using extra fields you will need to override the doSave() or save() method of the form and process the additional values to allow the form to save successfully.

A Note on Snippets: When using frameworks such as Symfony it is often the simplest pieces of code which are the hardest to either find or remember. These snippets are placed here for my own reference and will hopefully be useful to others. If you find them useful or have any suggestions, let me know.