How to configure Zend_Form to use array notation?

I find it difficult to configure Zend_Form. I have a subclass of Zend_Form class. The form contains some required information and some additional information. I want additional information to be available through an array. The presented data will look something like this:

$formData['required1']
$formData['required2']
$formData['addiotnalData']['aData1']
$formData['addiotnalData']['aData2']

I searched for this and tried all the suggestions I found (using subForms and setting the Zend_Form::setIsArray($flag)and methods Zend_Form::setElementsBelongTo($array)), but did not understand how to do this.

What am I doing wrong? How to set form element names so that I can access data using array notation?

+3
source share
2 answers

Sorted! The problem is using a custom decorator.

//In
$subForm = new Form_SubForm(); //this can be a Zend_Form or Zend_Form_SubForm     
$subForm->setIsArray(true);
$this->addSubForm($subForm, 'subform');

Elements will be displayed with identifier subform-elementnameand name subform[elementname].

+2
source

To expand the answer, because $ form-> setIsArray (TRUE) did not work with my custom decorator for elements. To render Zend_Form_Element, we needed our own ViewScript decorator.

The problem was rendering the name of the element using $ this-> element-> getName (). I had to use $ this-> element-> getFullyQualifiedName () in the ViewScript script decoder.

0
source

Source: https://habr.com/ru/post/1726062/


All Articles