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

Bug #6134 advcheckbox data not posted when ID is set on element
Submitted: 2005-12-03 02:51 UTC
From: phunkymunky at gmail dot com Assigned: avb
Status: Closed Package: HTML_QuickForm
PHP Version: 5.1.0 OS: FC4
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 46 - 3 = ?

 
 [2005-12-03 02:51 UTC] phunkymunky at gmail dot com
Description: ------------ Setting the ID of an advcheckbox element causes the element data not to be posted. This is caused as the hidden element is not updated properly. To get around the problem, the ID can be prefixed by '__': this causes the hidden element to be updated properly. This test script shows a small quickform followed by a var dump of the posted data. When both boxes are clicked, a value of 1 is expected to be seen underneath in the posted data for both values. The first checkbox data is never set as the id is set to the name of the element. When the id is set to the name of the hidden element, as per the second checkbox, the data is returned properly. Suggest prefixing the element ID with '__' when it is passed to createElement() as an attribute to fix this problem :) Test script: --------------- <?php require_once 'HTML/QuickForm.php'; $form = new HTML_QuickForm('form', 'post'); $form->addElement('advcheckbox', 'willfail', 'ID Set normally (id=willfail)', null, 'id=willfail'); $form->addElement('advcheckbox', 'willwork', 'ID Set with workaround (id=_willwork)', null, 'id=__willwork'); $form->addElement('submit', 'submit', 'Submit'); $form->display(); echo '<pre>'; echo var_dump($form->exportValues()); echo '</pre>'; ?> Expected result: ---------------- Expected result should show '1' for both fields array(3) { ["willfail"]=> string(0) "1" ["willwork"]=> string(1) "1" ["submit"]=> string(6) "Submit" } Actual result: -------------- Actual result only shows 1 for field with ID workaround array(3) { ["willfail"]=> string(0) "" ["willwork"]=> string(1) "1" ["submit"]=> string(6) "Submit" }

Comments

 [2006-06-03 15:11 UTC] avb (Alexey Borzov)
OK, looks like onclick javascript if (this.checked) { this.form['willfail'].value='1'; }else { this.form['willfail'].value=''; } addresses the element by id rather than by value Of course the best solution will be to throw away all javascript, since this stuff will work if one just prepends a hidden element to the checkbox bearing the same name. Unfortunately we have a couple of public methods that will become obsolete and ripping them out will break the Sacred Backwards Compatibility. So the temporary solution will be just to tell people not to set the id of the element equal to its name.
 [2006-06-20 16:46 UTC] avb (Alexey Borzov)
This bug has been fixed in CVS. 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. -- Removed all javascript, left the useless methods intact (but marked deprecated). The element now works as expected.