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:
- My Custom Definition List Form Formatter for Symfony
- Create a Div formatter (Scroll down to “Formatter”)
- Automatically mark required fields
- Create a custom formatter inline or with your own class
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.












17th Jun
Oncle Tom says:
Nice code and tip. Indeed it’s not a very documented area of sfForms.
Code digging ;-)
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!
22nd Jun
Oncle Tom says:
No problem :) you can also setup a global formatter from a project configuration file with
It’s pretty neat to override the default table one without modifying your forms definitions.
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.