Handling unspecified number of sub-forms with Zend_Form
Hello,
I have a form that can generate any number of input fields dynamically (the fields are generated using javascript).
The fields have some nested sub-form structure:
1. There can be many "feature" forms, and each has a name: features[feature0,..,featureN][name]
2. Each of these feature forms has many items, and each item has a name: features[feature0][items][item0,..,itemN][name]
(Actually they have many other fields except the name but this is enough for the example).
I managed to handle a static number of such sub-forms with Zend_Form, by attaching multiple instances of a FeatureForm to my main form, and attaching multiple instances of ItemForm to the FeatureForm (inside a container sub-form).
However, I wonder how can I add these sub-forms dynamically.
I thought about creating some pre-processing method that will get the $_POST data, inspect it and add fields accordingly before calling isValid().
Can anyone think of a better (more Zend_Form-like) way of handling such situation?
Thanks,
Sagi