ZF2 rendering subforms in fieldset

3k Views Asked by At

In Zend Framework 1 I did the following to render a subform in a fieldset:

$row = new Application_Form_Row();
$row->addDecorator('Fieldset');
$this->addSubForm($row, 'row['. $i . ']');

The individual 'row' subforms where then rendered in a fieldset and because of the pseudo array notation of the subform names (row[1], row[2], etc), the posted form data was neatly obtained as an array.

In ZF2 I can only do the rendering at the end, in my view script, with (custom) view helpers and perhaps partial view scripts.

As far as I can see the only way to render my (unknown number of) subforms is to loop through them in my view script.

How can I get my subforms in my view script as an array (or object) to loop through?

1

There are 1 best solutions below

0
On

This is quite good article about nesting fieldsets and array notation in ZF2 forms: http://www.michaelgallego.fr/blog/2012/07/04/new-zendform-features-explained/

However there are some limitation worth to read in "Adding new elements dynamically" section.