title: Fieldset implementation in Symfony forms
body: <p>on the project I am writing with Symfony, there will be fieldsets in forms very often, so I would like to create a mechanism so that I can group fields by fieldsets and still use the __toString() method of my forms.
  On <a href="http://www.symfony-project.org/forms/1_4/en/A-Widgets" rel="nofollow noreferrer">this page</a>, I read about the sfWidgetFormSchema, and how it could be considered as a widget, which enables to nest fields.
  So here is what I did:
  I created nested fields:</p>
  
  <pre><code>   $this-&gt;setWidgets(array(
        'customer'    =&gt; new sfWidgetFormSchema(array(
          'customer_name'      =&gt; new sfWidgetFormInputText(),
          'customer_email'     =&gt; new sfWidgetFormInputText(array())
        )),
        'library'     =&gt; new sfWidgetFormSchema(array(
          'library_name'      =&gt; new sfWidgetFormInputText(),
          'library_address'   =&gt; new sfWidgetFormInputText(),
          'library_city'      =&gt; new sfWidgetFormInputText(),
          'library_postcode'  =&gt; new sfWidgetFormInputText(),
          'library_website'   =&gt; new sfWidgetFormInputText()
        )),
        'message'     =&gt; new sfWidgetFormTextarea(array(),array( "cols" =&gt; 50, "rows" =&gt; 10 )),
      ));
  </code></pre>
  
  <p>Then I created a fieldsetFormSchemaFormatter class, which basically wraps fields in  tags, and associated it with the sfWidgetFormSchema fields:</p>
  
  <pre><code>foreach (array('customer', 'library') as $fieldset)
      {
        $this-&gt;widgetSchema[$fieldset]-&gt;addFormFormatter('tableless',
          new tableLessFormSchemaFormatter($this-&gt;widgetSchema['customer']));
        $this-&gt;widgetSchema[$fieldset]-&gt;setFormFormatterName('tableless');
        $this-&gt;widgetSchema[$fieldset]-&gt;setNameFormat('%s');
      }
      $this-&gt;widgetSchema-&gt;addFormFormatter('fieldset',
        new FieldsetFormSchemaFormatter($this-&gt;widgetSchema,
          'TableLessFormSchemaFormatter'));
      $this-&gt;widgetSchema-&gt;setFormFormatterName('fieldset');
  </code></pre>
  
  <p>And it just worked fine, I got my fieldset form. The problem I have is with validation, which is not at all described on the page I linked sooner in this question. The error messages appear on top of the form for all fields but the "message" field, which has an error message right after it. I don't think I'm gonna be able to get the error messages to display right after the rows and still use the echo $form construct without coding something ugly, so I think I'm gonna go with another implementation.
  I think that sfWidgetFormSchema widgets are meant to build interdependant fields, which would have global validation rules.</p>
  
  <p>How would you implement this fieldset functionality?</p>