Jump to content


This topic is now archived and is closed to further replies.


Zend Framework - Subform - element - setBelongsTo

Recommended Posts

Hi everyone,


I came across an annoying bug in Zend Framework and have been trying to find an answer through several forums.


The problem is that when I have a form and add a subform in in and add subform into that form and then add an element into the last subform which belongs to an array; Zend_Form loses one array from the middle.



$form = new Zend_Form();

$subForm1 = new Zend_Form_SubForm();

$subForm2 = new Zend_Form_SubForm();

$element = new \Zend_Form_Element_Text('textElement');


$subForm1->addSubForm($subForm2, 'subForm2');
$form->addSubForm($subForm1, 'subForm1');

echo $form->render();
// <input type="text" name="subForm1[subForm2][textElement]" id="subForm1-subForm2-textElement" value="">

// <input type="text" name="subForm1[subForm2][textThingsInArray][textElement]" id="subForm1-subForm2-textThingsInArray-textElement" value="">


How could I overcome this problem? This is making me mad... I couldn't find a patch anywhere for this issue


I know the Zend_Form_SubForm "overrides" the elements belongsTo but it's totally wrong; If elements in the subform belong to an array it doesn't mean that an element could not belong to some array itself and the array would then belong to the subforms belongsto option.

Share this post

Link to post
Share on other sites

If you really think this is a bug, why not report it so it can be fixed? Better still, why not try and fix it yourself and submit a patch?

Share this post

Link to post
Share on other sites

It seems like it's intentionally made that way.. But I looked into how Zend_Form builds the elements and subforms internally.. Didn't really get the hang of the logic.. Seems like at some point Zend forgets to add the array to the name of the element.


I was hoping that someone with a wider knowledge of Zend could have answered this question.. If this is unsuccessful I'll report to Zend and see what they say..

Share this post

Link to post
Share on other sites

There look to be a few open tickets regarding this name resolution behavior in the tracker already.  But please add another or bump/vote up an existing one.  I wonder if Zend_Form[_SubForm]::setElementsBelongTo() shares the same problem.

Share this post

Link to post
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.