ZF-3304: SubForms and their clones cannot always be modified separately

Issue Type: Bug Created: 2008-05-21T13:59:11.000+0000 Last Updated: 2012-08-31T09:08:15.000+0000 Status: Open Fix version(s): Reporter: Adam Jensen (jazzslider) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: Attachments:


Given the ZF trunk at revision 9496, cloned Zend_Form_SubForm objects behave rather unexpectedly. Specifically, it seems impossible to modify certain properties or elements of the clone without also modifying the original, and/or vice versa.

Consider the following reproduce code:

<pre class="highlight">
$form = new Zend_Form();
$form->setView(new Zend_View());

// Create the original SubForm
$subform1 = new Zend_Form_SubForm();
$subform1->addElement('text', 'given_name')
         ->addElement('text', 'family_name')
$form->addSubForm($subform1, 'me');

// Create a clone of the original SubForm and change it up a bit
$subform2 = clone $subform1;
$form->addSubForm($subform2, 'you');

// Populate the form with simulated $_POST values
$postedValues = array();
$postedValues['me']['given_name']   = 'Adam';
$postedValues['me']['family_name']  = 'Jensen'; 
$postedValues['you']['given_name']  = 'Someone'; 
$postedValues['you']['family_name'] = 'Else';

// Output the finished product;
// the values and legends for both forms should be different,
// as they were set differently above.
echo $form;

The actual result looks like this (here and in the expected result, I've added some line breaks and indents for readability):

<pre class="highlight">




Notice that the legends of both subforms are from $subform1 ("Me"), while the element values in both subforms are from $subform2 ("Someone" and "Else"). This contradicts the expected result below:

<pre class="highlight">



     the actual result, the values for the "me" subform are those assigned to the "you" subform, while the legend for the "you" subform is that assigned to the "me" subform. In a nutshell, we seem to have an identity crisis.

(By the way...I attempted to post this (twice) to the fw-mvc mailing list for community review, but my posting never showed up (either time). So, please forgive me if there's an easy solution to this problem that I would have found had my message gotten through to the mailing list :) )


Posted by Adam Jensen (jazzslider) on 2008-05-21T14:00:15.000+0000

Changing original priority; this isn't a particularly major problem, but it is a bit of an inconvenience.

Posted by Matthew Weier O'Phinney (matthew) on 2008-08-04T07:05:22.000+0000

Basically, we need to add a __clone() method that goes and clones each object attached to a given element, sub form, and display group... recursively. This is actually pretty tricky to achieve; I'm tentatively scheduling for 1.6, but it may be pushed to 1.7.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.