I would do like you do, inspect the post data. However, it would be nice
if you would just have to know the number of subforms you are
processing. Javascript can easily update a counter in a hidden field on
your mainform. It increments the count each time you add a subform
dynamically. This counter is the only post element you will have to
evaluate in order to know how many subforms to process.
Bart McLeod
Sagi Bashari schreef:
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