I have a form here in which there is a textfield which contains a number. In another part of the form there are rows, which coresponds with the number entered. For example 2 = 2 rows etc.
So my idea is to create one row which is duplicated by a javascript. So i must create a input element which name is in a array like name=”input[]” how can i do this in Zend Framework?
The only approach i found for this kind of problem is to use subforms. But every Subform has a explicite name which is not in a array.
To make a rendered
Zend_Formrespond to client-side changes – as in your example, to allow the user to enter the number of rows he wants – you need both client-side and server-handling.The best example demonstrating the general idea is from Jeremy Kendall:
jeremykendall.net » Blog Archive » Dynamically Adding Elements to Zend_Form
The upshot is that you have client-side code that adds tracks the number of fields and then a
preValidation()method that injects the right number of fields into the$forminstance beforeisValid()gets called.[As noted in the comments there, this
preValidation()processing could just be bundled intoisValid()so that the controller remains unchanged.]