QuickForm: setting value for checkboxes?
| From: | Jeffery Cann | Date: | Sun, 22 Sep 2002 23:42:33 +0000 |
| Subject: | QuickForm: setting value for checkboxes? | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-2362@lists.php.net to get a copy of this message | ||
Greetings.
I am trying to set a the value for list of checkboxes. Each checkbox value is
an id in a database. The user can select multiple checkboxes; thus,
selecting multiple database ids. When the form is processed, I would like to
retreive the list of ids selected by the user and do something with the list.
I would like to set the value of each checkbox equal to the database id, but I
have not been successful using QuickForm ($Id: QuickForm.php,v 1.27
2002/06/15 10:25:38 mansion Exp $)
Here's what i tried:
reset($collection); // an array of id = obj where obj is a mysql row
while (list ($id, $obj) = each ($collection)) {
$checkbox[] = &HTML_QuickForm::createElement('checkbox', "groupId[]",
'', $obj->theme);
}
The code above produces this HTML:
<input name="groupId[]" type="checkbox" value="1" />Open
discussion
What I want is the value attribute of the checkbox to be set equal to the $id
read from $collection (an array). So, for example if the particular database
id is 772, the HTML generated looks like this:
<input name="groupId[]" type="checkbox" value="772" />Open
discussion
where the value equals the $id from the database. So, I set the third
parameter to createElement to the $id variable:
&HTML_QuickForm::createElement('checkbox', "groupId[]", $id,
$obj->theme);
Finally, I tried to set the HTML element array manually:
&HTML_QuickForm::createElement('checkbox', "groupId[]", '',
$obj->theme,
"value=$id");
Both of produce the same HTML:
<input name="groupId[]" type="checkbox" value="1" />Open
discussion
I appreciate any suggestions.
--
Enable Your Information Age (c)
http://mridanga.com/