Musings of ErisDS
beta
ErisDS

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.

1
2
3
4
5
6
<?php
  // 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.

Related Posts

Share this...

  •  Add 'Snippet: Symfony Forms - Allowing Extra Fields' to Del.icio.us
  • Add 'Snippet: Symfony Forms - Allowing Extra Fields' to Twitter
  • Add 'Snippet: Symfony Forms - Allowing Extra Fields' to digg
  • Add 'Snippet: Symfony Forms - Allowing Extra Fields' to FURL
  • Add 'Snippet: Symfony Forms - Allowing Extra Fields' to reddit
  • Add 'Snippet: Symfony Forms - Allowing Extra Fields' to Technorati
  • Add 'Snippet: Symfony Forms - Allowing Extra Fields' to Newsvine
  • Add 'Snippet: Symfony Forms - Allowing Extra Fields' to Stumble Upon
  • Add 'Snippet: Symfony Forms - Allowing Extra Fields' to Google Bookmarks
  • Add 'Snippet: Symfony Forms - Allowing Extra Fields' to FaceBook

Comments

1 Comment to "Snippet: Symfony Forms – Allowing Extra Fields"
  1. 11th Aug

    limon says:

    You should add

    1
    $this->validatorSchema->setOption('filter_extra_fields', false);

    or the extra field input will be ignored. See “symfony Forms in Action”.

Add your thoughts

  • XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>