ZF-11504: Zend_From::addSubForms() issue after cloneing
Description
If you have a form with a subform with a name of numerical value
class My_Form extends Zend_Form {
public function init()
{
$this->addSubForm($mySubform, 0);
}
}
and you clone that form:
$form = new My_Form();
$form2 = clone $form;
you will get the following exception: "Invalid name provided; must contain only valid variable characters and be non-empty"
reason being the __clone method uses the addSubForms method and in the addSubFroms method it sets the $name = null and then never sets it to anything else unless the $key is a string. As you can see, the addSubfrom method allowed me to add a subform with a numeric name, therefore it is logical that the addSubForms() method would do the same.
If you remove line 1645-1648 of Zend_Form, it solves the problem:
$name = null;
if (!is_numeric($key)) {
$name = $key;
}
Comments
Posted by Enrico Zimuel (zimuel) on 2011-06-27T10:22:14.000+0000
I agree, the addSubForm() allows you to specify a numeric value as name, this means that addSubForms() should have the same behaviour. I will provide a fix and a unit test for that, thanks.
Posted by Enrico Zimuel (zimuel) on 2011-06-27T11:21:51.000+0000
Solved in trunk (commit 24155). Try it and let me know, thanks.
Posted by Brandon Mueller (fatmuemoo) on 2011-06-27T12:02:04.000+0000
Perfect, thanks for the quick response!
Posted by Enrico Zimuel (zimuel) on 2011-06-27T14:59:21.000+0000
Solved in branches/release-1.11 (commit 24156)