Musings of ErisDS
beta
ErisDS

By default Symfony displays forms in tables, with each new input being a table row. If you want to display your forms more semantically with fieldsets and lists, Symfony has a list formatter built in. You can tell an individual form to display as a list using the code below.

1
2
3
4
5
6
  <?php
    // lib/form/MyModelForm.class.php
    public function configure() {
      $this->widgetSchema->setFormFormatterName('list');
    }
?>

You can also create your own custom formatters. For detailed examples of how to do this see the following tutorials:

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, please let me know.

Related Posts

Share this...

  •  Add 'Snippet: Symfony Forms - Setting the Form Formatter' to Del.icio.us
  • Add 'Snippet: Symfony Forms - Setting the Form Formatter' to Twitter
  • Add 'Snippet: Symfony Forms - Setting the Form Formatter' to digg
  • Add 'Snippet: Symfony Forms - Setting the Form Formatter' to FURL
  • Add 'Snippet: Symfony Forms - Setting the Form Formatter' to reddit
  • Add 'Snippet: Symfony Forms - Setting the Form Formatter' to Technorati
  • Add 'Snippet: Symfony Forms - Setting the Form Formatter' to Newsvine
  • Add 'Snippet: Symfony Forms - Setting the Form Formatter' to Stumble Upon
  • Add 'Snippet: Symfony Forms - Setting the Form Formatter' to Google Bookmarks
  • Add 'Snippet: Symfony Forms - Setting the Form Formatter' to FaceBook

Comments

5 Comments to "Snippet: Symfony Forms – Setting the Form Formatter"
  1. 17th Jun

    Oncle Tom says:

    Nice code and tip. Indeed it’s not a very documented area of sfForms.
    Code digging ;-)

  2. 17th Jun

    ErisDS says:

    Thanks for the compliments. I love Symfony but anyone who uses it knows that the documentation is lacking. I hope to fill in a few gaps with my blog!

  3. 22nd Jun

    Oncle Tom says:

    No problem :) you can also setup a global formatter from a project configuration file with

    1
    sfWidgetFormSchema::setDefaultFormFormatterName('yourFormatter');

    It’s pretty neat to override the default table one without modifying your forms definitions.

  4. 29th Nov

    Rolf Ernst says:

    This only works with dynamically generated forms and not say forms generated via the the form generation commands with verbose templates. For that you have to generate a whole new model tree structure, mostly clone it and make manual changes. It’s a big drawback and I would hope the developers will fix it somehow that you can specify the formatter on the command itself. (Verbose templates generate a full form, not just the form generation tag). Since the CRUD operations for the front-end almost always result in you adjusting you the results for your specific needs (I add fieldset legends, turn on niceforms, etc.) this is a major pain in the neck.

  5. Snippet: Symfony Forms - Definition List Form Formatter | Musings of ErisDS

    13th May

    Snippet: Symfony Forms - Definition List Form Formatter | Musings of ErisDS pinged back:

    [...] List Form FormatterDisplaying forms as Definition ListsBack in April I posted a Snippet on Symfony Form Formatters. Since then I’ve done a bit more work with them and thought I’d share my custom form [...]

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>