I need to obtain something like this in zend
<input type="text" name="phone[1]" value="" />
<input type="text" name="address[1]" value="" />
<input type="text" name="banana[1]" value="whatever" />
Notice they have the same id inside the brackets! (i don’t need name="phone[]" , or name="phone[phone1]")
I’ve tried and
https://stackoverflow.com/a/3673034/579646 and
https://stackoverflow.com/a/406268/579646 and https://stackoverflow.com/a/7061713/579646
The problem is in ZendFramework i end up having to name 3 elements with the same name “1” and the last overwrites the previous. Even if i create 3 subforms i get the same effect.
Different examples show how to obtain an array with different indexes or no index([]), but i need different array to have the same index.
Thanks
Zend_Form has a feature for this named
setElementsBelongTo. Seehttp://framework.zend.com/manual/1.12/en/zend.form.advanced.html
The way of use this is setting to the Zend_Form object the prefix with
setElementsBelongTo, if you want iterate over each field then you can use subforms to encapsulate each group of fieldsYou can call to
setElementsBelongToin your controller or in theinit()method of your form class:gives
To get your expected result you will need remove some decorators (Form, dt, etc):
Then when you retrieve the values with
$form->getValues()the result is: