Home » HTML » HTML_QuickForm » Bug #6134
advcheckbox data not posted when ID is set on element
Details
| 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) |
Comments
[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"
}