Home » HTML » HTML_QuickForm » Bug #7288
'radio' 'checked' actually doesn't work
Details
| Request #7288 | 'radio' 'checked' actually doesn't work |
|---|---|
| Submitted | 2006-04-04 09:12 UTC |
| From | xl at kortkeros dot com |
| Status | Bogus |
| Package | HTML_QuickForm |
| PHP Version | 4.4.2 |
| OS | FreeBSD 4.11-STABLE |
| Roadmaps | (Not assigned) |
Comments
[2006-04-04 09:12 UTC] xl at kortkeros dot com
Description:
------------
'Checking' 'radio' elements by setChecked() or attributes actually doesn't work.
It's only works by setDefaults().
Similar requests:
HTML_QuickForm : Bug #491: when to addGroup("radio",$key) is passed key=0 name is not displayed
HTML_QuickForm : Bug #7148: Checked attribute alway true for radio button
HTML_QuickForm_Controller : Bug #3422: Adding radio buttons is incorrect
[2005-09-23 17:11 UTC] matthieu at phpmyvisites dot net
I agree with the 'bug' author that the behaviour of pear::QF on the "checked" state of a radio input is not normal or logical.
A user friendly approach would have been to allow to set
"checked=checked" by simply adding a array( 'checked' =>
'checked') argument to the addElement method.
Test script:
---------------
<?php
require_once("HTML/QuickForm.php");
$form = new HTML_QuickForm('testform');
$testRadio[0] = HTML_QuickForm::createElement ('radio', 'test1', 'Test radio1', '0', 0, null);
$testRadio[1] = HTML_QuickForm::createElement ('radio', 'test1', null, '1', 1, null);
$testRadio[1]->setChecked('checked');
$form->addGroup($testRadio, null, 'Test radio1', ' ');
$form->addElement ('radio', 'test2', 'Test radio2', '0', 0, null);
$form->addElement ('radio', 'test2', null, '1', 1, array('checked'=>'checked'));
$form->display();
?>
Expected result:
----------------
...
<tr>
<td align="right" valign="top"><b>Test radio1</b></td>
<td valign="top" align="left"><input name="test1" value="0" type="radio" id="qf_53ac95" /><label for="qf_53ac95">0</label> <input name="test1" value="1" type="radio" id="qf_2e4af2" checked="checked" /><label for="qf_2e4af2">1</label></td>
</tr>
<tr>
<td align="right" valign="top"><b>Test radio2</b></td>
<td valign="top" align="left"><input name="test2" value="0" type="radio" id="qf_cb6a8e" /><label for="qf_cb6a8e">0</label></td>
</tr>
<tr>
<td align="right" valign="top"><b></b></td>
<td valign="top" align="left"><input name="test2" value="1" type="radio" id="qf_a7f71e" checked="checked" /><label for="qf_a7f71e">1</label></td>
</tr>
...
Actual result:
--------------
...
<tr>
<td align="right" valign="top"><b>Test radio1</b></td>
<td valign="top" align="left"><input name="test1" value="0" type="radio" id="qf_53ac95" checked="checked" /><label for="qf_53ac95">0</label> <input name="test1" value="1" type="radio" id="qf_2e4af2" /><label for="qf_2e4af2">1</label></td>
</tr>
<tr>
<td align="right" valign="top"><b>Test radio2</b></td>
<td valign="top" align="left"><input name="test2" value="0" type="radio" id="qf_cb6a8e" checked="checked" /><label for="qf_cb6a8e">0</label></td>
</tr>
<tr>
<td align="right" valign="top"><b></b></td>
<td valign="top" align="left"><input name="test2" value="1" type="radio" id="qf_a7f71e" /><label for="qf_a7f71e">1</label></td>
</tr>
...