PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_QuickForm » Bug #4470

incorrect check of required checkbox field

Details

Submitted2005-05-30 01:54 UTC
Fromkris dot public at kauper dot net
Assignedavb
StatusClosed
PackageHTML_QuickForm
PHP Version4.3.10
OSFC2
Roadmaps(Not assigned)

Comments

[2005-05-30 01:54 UTC] kris dot public at kauper dot net

Description:
------------
HTML/QuickForm/RuleRegistry.php line 290 reads:

$value = " if (frm.elements['$elementName'].checked) {\n" .

This should be:

$value = " if (frm.elements['$elementName'].value) {\n" .

as the checkbox state is stored in a hidden input, and NOT a checkbox control.

To reproduce:

Create a form with a required checkbox field, and test the form. Notice that an validation error is generated whether or not the checkbox is ticked.

[2005-06-30 03:30 UTC] kris dot public at kauper dot net

I should have been more clear: this is an issue with both the checkbox element and the advcheckbox element.

The "checked" attribute should be queried for checkbox elements, but the "value" attribute should be queried for advcheckbox elements.

BTW, this appears to work fine on Win2k -- it's only an issue on my FC2 box (both same version: 3.2.4pl1)

[2005-06-30 10:31 UTC] kris dot public at kauper dot net

I've provided instructions on reproducing the bug. Sorry if that's not enough for you.

[2005-07-01 01:13 UTC] kris dot public at kauper dot net

How hard is it to follow the instructions I provided to reproduce the problem?

"To reproduce:

Create a form with a required checkbox field, and test the form. Notice
that an validation error is generated whether or not the checkbox is
ticked."

[2005-07-01 01:28 UTC] kris dot public at kauper dot net

// create form
$form =& new HTML_QuickForm("test", "post", "", "_self", null, true);
// add advcheckbox (similar problem exists for simple checkbox element as well)
$form->addElement("advcheckbox", "field1", "test");
// add "required" rule
$form->addRule("field1", "checkbox must be ticked", 'required', null, 'client');
// render
$renderer =& new HTML_QuickForm_Renderer_Array(true);
$form->accept($renderer);
// output to Smarty
$tpl->assign("form", $renderer->toArray());