ZF-12117: Clone Zend_Form will not update ID's
Description
When Cloning Zend_Form, the Id will not be updated thus causing ID Collisions.
Example:
$test = new Zend_Form();
$test->addElement('text', 'foo');
echo $test;
$new = clone $test;
echo $new;
Produces:
Recommend work around is to have a counter that will increment when the __clone method is called. Zend_Form should then append that number to the id:
class Zend_Form
{
protected static $_cloneCount = 0;
// ..snip ..
public function __clone()
{
self::$_cloneCount++;
$elements = array();
foreach ($this->getElements() as $name => $element) {
$element = clone $element;
$newId = $element->getId() . '-' . self::$_cloneCount;
$element->setAttrib('id', $newId);
$elements[] = $element;
}
$this->setElements($elements);
//duplicate below for display groups and subforms
}
}
Comments
Posted by Chuck Reeves (creeves1982) on 2012-03-22T16:36:14.000+0000
Sorry copied the clone wrong