formsdynamiczend-framework2zend-inputfilter

ZF2 refresh input filter after dynamicly adding elements to form


I have a form that triggers on event in __construct method to load some items from another modules . So far so good , a field set is loaded from the other module and added to the form and in the request->getPost() I have the data for the elements inside the fieldset , but the $form->getData() doesn't have the data for the fieldset.

I am calling $form->getInputFilter() before adding this fieldsets to the form and it seems that calling the $form->getInputFilter() dosn't creates the filters for the newly added elements . so how can i create inputfilters for the dynamic events without recreating the hole filters again ?

Or should i just delay calling $form->getInputFilter() untill all of the elemnts have been added to the form ?


Solution

  • I also added some elements to the form later what was ignored by the input filter.
    My solution is most likely not exactly the best one, but as you haven't received any other answers yet, here's what I did:

    I added
    use Zend\InputFilter\Factory as InputFactory;

    in the class where I'm validating the form data and then used

    $factory = new InputFactory(); 
    $form->getInputFilter()->add($factory->createInput(array(
        'name'     => 'title_str',
        'required' => true,
        'filters'  => array(
             array('name' => 'Int'),
        ),  
    )));