Jump to content

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.

 

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.

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..

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.