1
votes

I am trying to build multiple table form in zend framework 2. I have developed a single form by separating the field using HTML input array for example one field which belongs to table 'pages' looks like something

$this->add(array(
            'name' => 'pages[title]',
            'attributes' => array(
                'type' => 'text',
                'id' => 'title'
            ),
            'options' => array(
                'label' => 'Title',
            ),
        ));

But its filter is

$inputFilter->add($factory->createInput(array(
                        'name' => 'title',
                        'required' => true,
                        'filters' => array(
                            array('name' => 'StripTags'),
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name' => 'NotEmpty',
                            ),
                        ),
            )));

The reason behind changing name is I am validating field step by step by assigning the values accordingly in my controller like following

$form->setData($this->request->getPost()->pages);

The problem is occurring while getting the array of messages. Form isValid() function is working fine but it returns empty array of messages in case of invalid input. How can I get the messages?


Upon digging deeper I have found out that filter is returning messages but when form is mapping error messages through the name of filter and element and as I am using different names it is unable to map... nay work around for this

And before you ask me to assign the same names to form elements and filters it will won't work because the form can't assign data to element with pages[title] because in request it won't receive any input with name pages[title] rather it will receive array of pages

1

1 Answers

1
votes

I would take another approach, Keep your names simple, without adding in array name notation.

then you can validate different steps by using Validation Groups and Fieldsets.

http://framework.zend.com/manual/2.0/en/modules/zend.form.quick-start.html#validation-groups

If you can give more details about exactly what you're trying to achieve it will be easier to respond.