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

Bug #15359 fatal error when appendName is set to false for a group with a group rule
Submitted: 2008-12-19 23:54 UTC
From: gery Assigned: wiesemann
Status: Verified Package: HTML_QuickForm_DHTMLRulesTableless (version 0.3.3)
PHP Version: 5.2.5 OS:
Roadmaps: (Not assigned)    
Subscription  


 [2008-12-19 23:54 UTC] gery (Gery Flament)
Description: ------------ A php fatal error occurs if the optional parameter "appenName" is set to false in the method HTML_QuickForm::addGroup and a group rule is added to the group. The fatal error is : Fatal error: Call to undefined method HTML_QuickForm_Error::getAttribute() in C:\wamp\bin\php\php5.2.5\PEAR\HTML\QuickForm\DHTMLRulesTableless.php on line 248 Test script: --------------- require_once 'HTML/QuickForm/DHTMLRulesTableless.php'; require_once 'HTML/QuickForm/Renderer/Tableless.php'; $form = new HTML_QuickForm_DHTMLRulesTableless('example'); $id['lastname'] = &HTML_QuickForm::createElement('text', 'lastname', 'Name', array('size' => 30)); $id['code'] = &HTML_QuickForm::createElement('text', 'code', 'Code', array('size' => 5)); $form->addGroup($id, 'id', 'ID', ', ', false); $form->addGroupRule('id', array( 'lastname' => array( array('Name is required', 'required', null, 'client') ) )); $form->addElement('submit', null, 'Submit'); $form->getValidationScript(); $renderer =& new HTML_QuickForm_Renderer_Tableless(); $form->accept($renderer); echo $renderer->toHtml(); Expected result: ---------------- The form is rendered and there is a javascript validation on the first element of the field group. The HTML for the element group should be :
Actual result: -------------- The form is not rendered, a fatal error is displayed : Fatal error: Call to undefined method HTML_QuickForm_Error::getAttribute() in C:\wamp\bin\php\php5.2.5\PEAR\HTML\QuickForm\DHTMLRulesTableless.php on line 248

Comments

 [2008-12-26 20:40 UTC] wiesemann (Mark Wiesemann)
Thanks for investigating this bug. Your patch changes bigger parts of the existing code. May I ask how you have tested your changes? Did you only use the bundled example file and the example provided here in the bug report? And are you sure that the for loop really only applies to radio buttons? (I haven't tested it today but I'd expect at least also checkboxes there.) It would be nice if you could provide a real patch next time ("cvs diff -u ...") [not a requirement, but it's easier that way], and if you could use four spaces instead of one tab, thanks.
 [2008-12-30 23:04 UTC] gery (Gery Flament)
I tested by using a file of my own, with all the basic HTML form elements. I made other test files, using the bundled "groups" example from /PEAR/docs/HTML_QuickForm/docs/groups/php to which I added some fieds in order to have all the basics HTML elements : http://gery.flament.free.fr/en/Development/pear/tests_patch_prepend/groups_test_default.php I have used a modified version of the patch I published here, where I put the lines to correct the bug 15301 otherwise it would have been difficult to test. Yes, I'am sure that the loop only applies to radio buttons, because $elements[$i]->getAttribute('name') returns the name you give to the element when creating it with HTML_QuickForm::createElement and not the name of the input element that is actually created. I saw that by making an echo. So if (strpos($elements[$i]->getAttribute('name'), $groupElementName) === 0) is true only for a group of radio buttons where the name of the elements are the same as the name of the group they are part of. By the way with the bundled "groups" file, you will notice that the "Yes/No" element is created using a code where no name are specified for the elements of the group : // Creates a standard radio buttons group $radio[] = &HTML_QuickForm::createElement('radio', null, null, 'Yes', 'Y'); $radio[] = &HTML_QuickForm::createElement('radio', null, null, 'No', 'N'); $form->addGroup($radio, 'iradYesNo', 'Yes/No:', null); And so in this case, the test above returns false even for a radio. My patch corrects also that. So for groups composed with other elements than radio buttons, the display of the error for the "required" rule remains even when the user corrects it and leave the fields. But It's not so simple to change that because you can have some rules that require that more than one element is to be filled or checked. And to my opinion, the error shouldn't appear as soon as the user leave the first element. Ok for providing a diff file next time. Thank you.