ZF2 has added formCollection and it let’s you dynamically add formElements after the page has loaded.
I have a table of dynamic amount of rows which should each have a textfield like:
foreach ($types as $type) :
?>
<tr><td><?php echo $type ?></td><td><?php echo $this->formRow($form->get('amount')); ?></td></tr>
<?php
endforeach;
I’m looping through an array of items and printing the rows/columns for my table but it seems that formCollection only allows you to print all of the fields at once.
Is it possible to perhaps print one of the textfields each loop? All of the documentation talks about dynamically adding elements using a template and JavaScript. But I basically just want an array of inputs that I already know the amount to.
It seems I can’t change the count of them in my controller either. Tried this:
$types = array(1,2,3,4,5)
$form = new ThingsForm();
$form->get('amounts')->setOptions(array(
'count' => count($types)
));
I tried just having count => 1 of the collection and then printing many of them but when you fill them it only gets treated as one item.
Shorter, more usefull version: