PEAR is archived and read-only

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

Home » HTML » HTML_QuickForm2 » Bug #4564

Checkboxes can't be created with arbitrary value

Details

Request #4564Checkboxes can't be created with arbitrary value
Submitted2005-06-09 14:52 UTC
Fromalands at baraodemaua dot br
Assignedavb
StatusClosed
PackageHTML_QuickForm2
PHP Version4.3.0
OSWindows 2000
Roadmaps0.1.0

Comments

[2005-06-09 14:52 UTC] alands at baraodemaua dot br

Description:
------------
When I create a checkbox field using the HTML_QuickForm::createElement this one comes with attribute value set to 1 and I need to change that value but in the constructor of the checkbox (HTML_QuickForm_checkbox) has a code that update the attribute value only. I think that all attributes need to be updated.

Reproduce code:
---------------
My code:

$res =& $db->query(" select idModule, name from module where status='1' order by name ");
while($res->fetchInto($row)) {
$formChecks[] = &HTML_QuickForm::createElement('checkbox', 'perm[]', null, $row['name'], array('value'=>$row['idModule']));
}
$form->addGroup($formChecks, null, null, "<br>\n");

Code where I think the error is in the constructor of HTML_QuickForm_checkbox:

$this->updateAttributes(array('value'=>1));

Code I think that resolv the problem:

$this->updateAttributes($attributes);

Expected result:
----------------
Checkboxes with defined values.

Actual result:
--------------
Checkboxes with value attribute equal 1

[2005-07-04 17:00 UTC] lionel dot poussin at gmail dot com

I'm also using this class and can confirm that wathever you use (constructor parameter $elementLabel, array('value'=>[myValue]) in constructor parameter $attributes, or setValue function), you always get a checkbox with a value of 1

[2005-07-27 21:07 UTC] mark at slosarek dot com

Changing the line in the constructor for checkbox from

$this->updateAttributes(array('value'=>1));

to

if (!isset($attributes['value']))
$this->updateAttributes(array('value'=>1));

allows the value of the checkbox to be set in the attribute field with the the argument 'value'=>'arbitrary value'