ZF-5842: When cloning subforms, reset elementsBelongTo value

Issue Type: Sub-task Created: 2009-02-19T08:50:24.000+0000 Last Updated: 2012-11-20T21:38:11.000+0000 Status: Open Fix version(s): Reporter: Matthew Weier O'Phinney (matthew) Assignee: None Tags: - Zend_Form

Related issues: Attachments:


When cloning sub forms, output can be problematic if the original sub form has already been rendered. In such a case, if the cloned sub form has been assigned a different name, the original elementsBelongTo value will persist and be used during output. As an example:

<pre class="highlight">

$clone = clone $subForm;
echo $clone->render();

When the $clone is rendered, its items will still be subscripts of 'foo', not 'bar'.

The solution is to modify setName() slightly to detect such a situation:

<pre class="highlight">
    public function setName($name)
        $updateElementsBelongTo = false;
        if ($this->getElementsBelongTo() == $this->getName()) {
            $updateElementsBelongTo = true;

        $name = $this->filterName($name);
        if (('0' !== $name) && empty($name)) {
            require_once 'Zend/Form/Exception.php';
            throw new Zend_Form_Exception('Invalid name provided; must contain o

        $this->setAttrib('name', $name);

        if ($updateElementsBelongTo) {
        return $this;


No comments to display

Have you found an issue?

See the Overview section for more details.


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

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