title: Populating Form Data in ZF2 when using Fieldsets
body: <p>I am currently playing around with ZF2 beta 4 and I seem to be stuck when i try to use fieldsets within a form and getting the data back into the form when the form is submitted. I am not sure if I am not setting the input filters right for fieldsets or I am missing something. For example, I have the following (simplified to make it clear):</p>
  
  <p><strong>Controller</strong>
  </p>
  
  <pre><code>public function indexAction(){
     $form = new MyForm();
     $request = $this-&gt;getRequest();
            if ($request-&gt;isPost()) {
                   $form-&gt;setData($request-&gt;post());
                   if ($form-&gt;isValid()) {
                          //Do something
                          print_r($form-&gt;getData()); //for debug
                   }
            }
     return array('form' =&gt; $form);
  }
  </code></pre>
  
  <p><strong>MyForm.php</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>class MyForm extends Form
  {
      public function __construct()
      {
          parent::__construct();
          $this-&gt;setName('myForm');
          $this-&gt;setAttribute('method', 'post');
  
          $this-&gt;add(array(
                      'name' =&gt; 'title',
                      'attributes' =&gt; array(
                      'type'  =&gt; 'text',
                      'label' =&gt; 'Title',
                      ),
                   ));
  
          $this-&gt;add(new MyFieldset('myfieldset'));
  
          //setting InputFilters here
          $inputFilter = new InputFilter();
          $factory = new InputFactory();
  
          $inputFilter-&gt;add($factory-&gt;createInput(array(
              'name'     =&gt; 'title',
              'required' =&gt; true,
              'filters'  =&gt; array(
                  array('name' =&gt; 'StripTags'),
                  array('name' =&gt; 'StringTrim'),
              ),
          )));
  
          //Now add fieldset Input filter
          foreach($this-&gt;getFieldsets() as $fieldset){
                $fieldsetInputFilter = $factory-&gt;createInputFilter($fieldset-&gt;getInputFilterSpecification());
                $inputFilter-&gt;add($fieldsetInputFilter,$fieldset-&gt;getName());
          }
  
          //Set InputFilter
          $this-&gt;setInputFilter($inputFilter);
      }
  }
  </code></pre>
  
  <p><strong>MyFieldset.php</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>class MyFieldset extends Fieldset implements InputFilterProviderInterface{
      public function __construct($name)
      {
          parent::__construct($name);
          $factory = new Factory();
  
          $this-&gt;add($factory-&gt;createElement(array(
              'name' =&gt; $name . 'foo',
              'attributes' =&gt; array(
                  'type'  =&gt; 'text',
                  'label' =&gt; 'Foo',
              ),
          )));
      }
  
      public function getInputFilterSpecification(){
          return array(
              'foo' =&gt; array(
                  'required' =&gt; true,
                  'filters'  =&gt; array(
                      array('name' =&gt; 'StripTags'),
                      array('name' =&gt; 'StringTrim'),
                  ),
              ),
          );
      }
  }
  </code></pre>
  
  <p>I am able to output the form as expected and I end up with two input elements named 'title' and 'myfieldsetfoo' (the name given when outputing with the ViewHelper). So of course when I submit the raw post will show values for 'title' and 'myfieldsetfoo'. However, when I use SetData() the values for the field set are not being populated (although I can see the values in the raw post object). Instead, examining the output of '$form->getData()' I receive:</p>
  
  <pre><code>Array(
     [title] =&gt; Test,
     [myfieldset] =&gt; Array(
                           [foo] =&gt;
                          )
  )
  </code></pre>
  
  <p>What am I missing? What do I need to do so that ZF2 understands how to populate the fieldset?</p>
  
  <p>Thanks for any help, this is driving me crazy.</p>