Home » HTML » HTML_QuickForm » Bug #4840
if select data is an accociative array w. '0' as first index, a freeze is buggy
Details
| Submitted | 2005-07-15 13:11 UTC |
|---|---|
| From | hockeyhawk at gmx dot net |
| Status | Duplicate |
| Package | HTML_QuickForm |
| PHP Version | 4.3.10 |
| OS | SuSE Linux 9.2 |
| Roadmaps | (Not assigned) |
Comments
[2005-07-15 13:11 UTC] hockeyhawk at gmx dot net
Description:
------------
HTML_QuickForm: 3.2.4pl1
Element: HTML_QuickForm::Select
If you populate a select element with an accociative array, that has a '0' as first index, the freeze Method will produce invalid output, if any other option than the first is actually selected.
Please look at the following code. The only difference in the Select's data is the first array item. In $selValuesAssoc1 it is index by a '0' in $selValuesAssoc2 it's '1' (or everything different than '0').
Don't change anything in the form, just click the button, that will freeze the form.
Now you'll see that the first data item is selected in the first select-element. But that is just the visible thing. Inspecting the HTML code shows that the "value" is still "Val2" for the second data entry.
Reproduce code:
---------------
<?php
require_once "HTML/QuickForm.php";
$form = new HTML_QuickForm('frmSelectBug', 'get');
$form->addElement('header', 'header1', 'Select data is a associative array first entry indexed \'0\' - 2nd selected');
$selValuesAssoc1 = array('0'=>'Value 1', 'Val2'=>'Value 2', 'Val3'=>'Value 3');
$obj = &HTML_QuickForm::createElement('select', 'cbxBug', '2nd Item is selected!:', $selValuesAssoc1);
$obj->setValue('Val2'); // select 2nd entry
$form->addElement($obj);
$form->addElement('header', 'header2', 'Select data is an associative array first entry indexed \'1\' - 2nd selected');
$selValuesAssoc2 = array('1'=>'Value 1', 'Val2'=>'Value 2', 'Val3'=>'Value 3');
$obj = &HTML_QuickForm::createElement('select', 'cbxNormal', '2nd Item is selected!:', $selValuesAssoc2);
$obj->setValue('Val2'); // select 2nd entry
$form->addElement($obj);
if($form->validate())
$form->freeze();
else
{
$obj = &HTML_QuickForm::createElement('submit', 'btnSubmit', 'Freeze form!');
$form->addElement($obj);
}
$form->display();
?>
Expected result:
----------------
After clicking "Freeze form!" both select's should remain on "Value 2".
Actual result:
--------------
It seems Select #1 switches back to "Value 1". But looking at the source code the value is "Val 2"!