Date: 12/05/00
- Next message: Matthew Leingang: "[phplib] Re: How do I abort the Loginwindow"
- Previous message: Markus Wagner: "[phplib] How do I abort the Loginwindow"
- Next in thread: Jeffrey A. Stuart: "RE: [phplib] tpl_form, Checkboxes and multiple option."
- Reply: Jeffrey A. Stuart: "RE: [phplib] tpl_form, Checkboxes and multiple option."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I (like many people I guess..) am having problems with checkboxes in PHPlib.
I have a form, which adds an entry into a database, I then want to allow the
user to edit this entry later if the wish. The form has 10 checkboxes, I am
creating them with the "multiple" option set. Then I implode the resulting
array from the checkboxes and store it in a database.
Now, to edit the entry, I explode the entry from the database into an array
and I recreate the same form, with the intention to show all of the user's
previous choices as checked. However, I cannot find a way to set the
checkboxes as checked or unchecked. I know _which_ ones should be checked,
that's not a problem. But the "checked"=>"1" option does not work when
"multiple" is set, and if I use "extrahtml"=>" checked" it sets _all_ of the
checkboxes to checked.
Now, in the file of_checkbox.inc in PHPlib, there is this function...
function of_checkbox($a) {
<snip>
if ($this->multiple) {
$n = $this->name . "[]";
$str .= "<input type='checkbox' name='$n' value='$val'";
if (is_array($this->value)) {
reset($this->value);
while (list($k,$v) = each($this->value)) {
if ($v==$val) {
$str .= " checked";
break;
<snip>
it seems to me (maybe I'm wrong) that there should be some way to control if
a checkbox is checked, even when the multiple option is set, check out the
following two lines from the function...
if ($v==$val) {
$str .= " checked";
Here is some of my code in case you need to see what I'm trying to do...
// this is in the add.inc , it creates the checkboxes from an array
// $this->access_array contains the info for all my checkboxes
for($x = 0; $x < sizeof($this->access_array); $x++)
{
$this->form_data->add_element(array("type"=>"checkbox",
"name"=>"accessories",
"value"=>$this->access_array[$x]["id"],
"multiple"=>"1"
));
}
// this is in the edit.inc, it creates the same checkboxes, but it makes
// a distinction between which checkboxes should be checked, and which
// ones shouldn't
// $this->access_array is the same as the one above
// $old_accessories is the array from the database containing the user's
// previous choices...
for($x = 0; $x < sizeof($this->access_array); $x++)
{
if(in_array($old = $this->access_array[$x]["id"], $old_accessories))
{
$this->form_data->add_element(array("type"=>"checkbox",
"name"=>"accessories",
"value"=>$this->access_array[$x]["id"],
"multiple"=>"1"
// this one should be checked
));
}
else
{
$this->form_data->add_element(array("type"=>"checkbox",
"name"=>"accessories",
"value"=>$this->access_array[$x]["id"],
"multiple"=>"1"
// this one is not checked
));
}
}
// this is how I display the checkboxes in both add.ihtml and edit.ihtml
for($x = 0; $x < sizeof($this->access_array); $x++)
{
$this->form_data->show_element("accessories",
$this->access_array[$x]["id"]);
echo $this->access_array[$x]["name"] . "<br>";
}
I don't think something like this would have been overlooked in PHPLib, so
either I'm not doing something right, or I'm going about this in the wrong
direction. If you need to see more code or anything I'm doing, just ask. I
would really appreciate any help.
Thanks
Joel Kucera
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>
- Next message: Matthew Leingang: "[phplib] Re: How do I abort the Loginwindow"
- Previous message: Markus Wagner: "[phplib] How do I abort the Loginwindow"
- Next in thread: Jeffrey A. Stuart: "RE: [phplib] tpl_form, Checkboxes and multiple option."
- Reply: Jeffrey A. Stuart: "RE: [phplib] tpl_form, Checkboxes and multiple option."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

