I've got a form class that dynamically creates fieldsets with elements/fieldsets recursively. I do this to get settings[general][rpp][value]
as an input name (for example). The fields get generated because the settings are user defined in an XML file.
Fieldsets are getting created like this:
$fieldset = new Fieldset(...);
$fieldset->add(...);
$form->add($fieldset);
The form is being output correctly; everything works. Except i need validation.
My goal is to define validators and filters for these nested elements. I'm really confused at how it works - but it looks like just the form itself defines an input_filter setInputFilter(...)
and i don't know how to get it to recognize the recursion without a factory and proprietary classes for the fieldsets instead of being dynamic.
Am i clear?
Thanks.
here, in the ZF2 docs is explained as well http://framework.zend.com/manual/2.3/en/modules/zend.form.collections.html
I've figured out how to do this highly dynamic type of form with validation and filters. I will explain here with this hypothetical script:
So you can see you have to create input filters for each set of elements and each fieldset and then work backwards through them adding them to each other until the main input filter is built and you can assign it to the form instance.
This then would use the supplied validators with input names such as
general[setting_1]
after running$form->setData($this->request->getPost())
-$form->isValid()
This response could be 100 times more detailed, but it's better than what is available on the subject of dynamic fieldset validation.