johnny86 Posted October 28, 2011 Share Posted October 28, 2011 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. Demonstration: <?php $form = new Zend_Form(); $subForm1 = new Zend_Form_SubForm(); $subForm2 = new Zend_Form_SubForm(); $element = new \Zend_Form_Element_Text('textElement'); $element->setBelongsTo('textThingsInArray'); $subForm2->addElement($element); $subForm1->addSubForm($subForm2, 'subForm2'); $form->addSubForm($subForm1, 'subForm1'); echo $form->render(); // NOT EXPECTED! // <input type="text" name="subForm1[subForm2][textElement]" id="subForm1-subForm2-textElement" value=""> // THIS IS EXPECTED // <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. Quote Link to comment https://forums.phpfreaks.com/topic/249975-zend-framework-subform-element-setbelongsto/ Share on other sites More sharing options...
trq Posted October 28, 2011 Share Posted October 28, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/249975-zend-framework-subform-element-setbelongsto/#findComment-1282961 Share on other sites More sharing options...
johnny86 Posted October 28, 2011 Author Share Posted October 28, 2011 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.. Quote Link to comment https://forums.phpfreaks.com/topic/249975-zend-framework-subform-element-setbelongsto/#findComment-1282968 Share on other sites More sharing options...
thehippy Posted October 28, 2011 Share Posted October 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/249975-zend-framework-subform-element-setbelongsto/#findComment-1282988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.