title: How to custom render a ZF2 Collection with matching fieldset
body: <p>I've created a standard application using collections to map one to many relationships (without using Doctrine) pretty much the way it is being described in <a href="http://framework.zend.com/manual/2.2/en/modules/zend.form.collections.html" rel="nofollow">http://framework.zend.com/manual/2.2/en/modules/zend.form.collections.html</a> and I have something like the following code:</p>
  
  <pre><code>class Person {
    protected $attrributes;
  } 
  
  class Attribute {
    protected $attr1;
    protected $attr2;
  }
  </code></pre>
  
  <p>I've created the <code>AttributeFieldset</code> and the matching <code>AttributeForm</code> required and I've added the <code>AttributeFieldset</code> on my <code>PersonForm</code>:</p>
  
  <pre><code>$this-&gt;add(
    array(
      'type' =&gt; 'Zend\Form\Element\Collection',
      'name' =&gt; 'attributes',
      'options' =&gt; array(
        'label' =&gt; _("Add person attribute"),
        'count' =&gt; 1,
        'should_create_template' =&gt; true,
        'allow_add' =&gt; true,
        'target_element' =&gt; array(
          'type' =&gt; 'Persons\Form\AttributesFormFieldset'
        )
      )
    ));
  </code></pre>
  
  <p>Calling the <code>$this-&gt;formCollection()</code> view helper will generate the default HTML for the collection and the data template to add new attributes dynamically via javascript as specified in the documentation.</p>
  
  <p>However what I would like to accomplish is to have a table listing with all the existing attributes of the person, with an edit/delete option and create a modal window with the collection fieldset to add new attributes to the Person.</p>
  
  <p>Imagine the following html:</p>
  
  <pre><code>&lt;a href="#" onclick="add(this); return false;"&gt;Add new attribute&lt;/a&gt;
  &lt;table&gt;
    &lt;? foreach( $this-&gt;person-&gt;attributes as $attribute ): ?&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;?= $attribute['attr1']; ?&gt;&lt;/td&gt;
        &lt;td&gt;
          &lt;a href="#" onclick="edit(this); return false"&gt;Edit&lt;/a&gt; | &lt;a href="#" onclick="delete(this); return false"&gt;Delete&lt;/a&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;? endforeach; ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I know I can skip the formCollection entirely and add <code>&lt;input type="hidden"&gt;</code> tags the way ZF2 Collection would expect them (e.g. <code>attribute[0][attr1]</code> etc) on each row I add to my table and have the form created dynamically but I am guessing that I will be missing out on the ZF2 InputFilters.</p>
  
  <p>Is there a better way to accomplish this? Has anyone done it before?</p>