Home » HTML » HTML_QuickForm » Bug #4645
Group Element Named '0' not able to getValue()
Details
| Submitted | 2005-06-20 21:17 UTC |
|---|---|
| From | gthorne at eportation dot com |
| Assigned | avb |
| Status | Closed |
| Package | HTML_QuickForm |
| PHP Version | 4.3.10 |
| OS | Fedora Core 3 |
| Roadmaps | (Not assigned) |
Comments
[2005-06-20 21:17 UTC] gthorne at eportation dot com
Description:
------------
PEAR Package HTML_QuickForm 3.2.4pl1
I have an element named '0' created in this code:
$vehicle[] =& $form->createElement('hidden', 'type', 'checkbox');
$vehicle[] =& $form->createElement('checkbox', 1, 1, 'Yes');
$vehicle[] =& $form->createElement('checkbox', 0, 0, 'No');
$form->addGroup($vehicle, 'is_vehicle', "Is Vehicle", array(" "));
I am trying to retrive the value of the element named '0'. However the code in HTML_QuickForm_group->setValue does not allow for this instance.
the code looks for !empty($elementName) this does not allow for the (int) 0 or (string) 0.
Unfortunatly, I cannot change the name of the element.
a possible fix is below ( around line 166 group.php ):
$index = ( !empty($elementName) || ($elementName === 0 || $elementName === "0") ) ? $elementName : $key;
Reproduce code:
---------------
$vehicle[] =& $form->createElement('hidden', 'type', 'checkbox');
$vehicle[] =& $form->createElement('checkbox', 1, 1, 'Yes');
$vehicle[] =& $form->createElement('checkbox', 0, 0, 'No');
$form->addGroup($vehicle, 'is_vehicle', "Is Vehicle", array(" "));
foreach( $val as $k=>$v){
$element =& $form->getElement($k);
$element->setValue($v);
}
Expected result:
----------------
element is_vehicle[0] to be checked
Actual result:
--------------
element is_vehicle[0] is not checked