Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.3.2

Bug #19477 Broken element names with nested container groups
Submitted: 2012-06-20 20:18 UTC
From: cweiske Assigned: avb
Status: Closed Package: HTML_QuickForm2 (version 2.0.0RC1)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2012-06-20 20:18 UTC] cweiske (Christian Weiske)
Description: ------------ The names of elements that are within 2 nested container groups are strangely broken: The first name has 4 [] nestings ("test[1][1][1][name]"), the second and third elements 3 ("test[1][2][name]"), the fourth element has again 4 [] nestings ("test[2][2][2][name]"). This is kind of unpredictable, and makes acessing the element's values hard. Test script: --------------- <?php require_once 'HTML/QuickForm2.php'; require_once 'HTML/QuickForm2/Container/Group.php'; require_once 'HTML/QuickForm2/Element/InputText.php'; $form = new HTML_QuickForm2('form'); $group = new HTML_QuickForm2_Container_Group('test'); for ($n = 1; $n < 3; $n++) { $subgroup = new HTML_QuickForm2_Container_Group($n); for ($m = 1; $m < 3; $m++) { $subsubgroup = new HTML_QuickForm2_Container_Group($m); $subsubgroup->addElement(new HTML_QuickForm2_Element_InputText('name')); $subgroup->addElement($subsubgroup); } $group->addElement($subgroup); } $form->addElement($group); echo $form; ?> Expected result: ---------------- <input id="name-0" type="text" name="test[1][1][name]"> <input id="name-1" type="text" name="test[1][2][name]"> <input id="name-2" type="text" name="test[2][1][name]"> <input id="name-3" type="text" name="test[2][2][name]"> Actual result: -------------- <input id="name-0" type="text" name="test[1][1][1][name]"> <input id="name-1" type="text" name="test[1][2][name]"> <input id="name-2" type="text" name="test[2][1][name]"> <input id="name-3" type="text" name="test[2][2][2][name]">

Comments

 [2012-06-21 23:22 UTC] avb (Alexey Borzov)
-Status: Open +Status: Verified -Assigned To: +Assigned To: avb
Confirmed this. Here is a much simpler test case: ---------- $group = new HTML_QuickForm2_Container_Group('foo[foo]'); $text = $group->addElement(new HTML_QuickForm2_Element_InputText('bar')); $group->setName('test[foo][foo]'); echo $text->getName(); ---------- This outputs test[foo][foo][foo][bar] instead of expected test[foo][foo][bar] Looks like the culprit is array_search() in Group::renameChild() which finds the first occurence of 'foo' instead of the last one. I ain't even sure that array_search() is needed...
 [2012-06-22 00:52 UTC] avb (Alexey Borzov)
-Status: Verified +Status: Closed
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.