Hi, there! I wanna create a form like the above image through the zend framework 2. The input fields will be like:
1. dependent_features[0], 2. dependent_features[1] etc
and their corresponding independent features like:
1. independent_features[0][], 2. independent_features[1][] etc.
Now, how can I generate this kind of form with the collection input fields as well as its validations?
See https://docs.zendframework.com/zend-form/collections/#creating-fieldsets
First, let Zend Form define your HTML. (Not the other way around).
For example, for your case you can define 3 classes:
ParentContainer
, which contains Collection ofDependentFeature
Fieldsets. EachDependentFeature
Fieldset contains Select element, and a Collection ofIndependentFeature
Fieldsets. EachIndependentFeature
Fielset contains a single Select element.Resulting HTML came out like this:
In other words, define the Collection of elements, nest them, and let Zend do the HTML work for you.
Using Zend Form Annotations you can do something like this:
Create the form like so:
If you are not using Annotations, you can still build it as I mentioned above -> by nesting Collection of Fieldsets into you Collection of Fieldsets.
How exactly you name and nest your elements depends on your exact domain requirements.