Forum Moderators: coopster

Message Too Old, No Replies

intereting php checkbox question

         

willg825

5:49 pm on Jul 23, 2004 (gmt 0)

10+ Year Member



Hi all, I have a question related to PHP/checkboxes. I have a form, which when submitted, checks the form for blank fields, misentered fields, etc., and if there are errors, returns back to the original form. All of the input 'text' boxes in the form have their value set to '$_POST[value]' so they dont have to re-enter any information. I want to achieve a similar effect with the 2 checkboxes I have - a categories[] array and a funding[] array. Before each <input type=checkbox I have the following:

if(isset($_POST[categories]) {
if (!is_bool(strripos(implode(",", $_POST[categories]),"Checkbox Value")))
$checked="checked";
else $checked="";
}
and then int he input, I call the variable $checked, which is either 'checked' or blank. I get the followin g errormsg: Warning: implode() [function.implode]: Bad arguments. (referring to each line)

I've tried a variety of different things here - I also tried doing if(isset($_POST['categories[0]']))$checked="checked";else $checked=""; to no avail. I've searched and searched and cant seem to find anyone with a similar situation....

Does anyone have any recommendations for the best way for the checkboxes that were checked to be re-checked when the form loads again? Or can find something wrong with my use of implode, and why its not working here? Thanks - I know this problem is a little convoluted...

-will

httpwebwitch

8:37 pm on Jul 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$checkboxname="things";

$checkboxarray=explode(",",$_POST[$checkboxname]);
// this gets the POSTed stuff and puts
// it back into a handy array

// if you're going to loop, start it here

$checkboxvalue='cheese';

// write the beginning of the tag.
print("<input type='checkbox' name='".$checkboxname."[]' value='".$checkboxvalue."'");

// does it get the "checked" attribute?
if (in_array($checkboxvalue,$checkboxarray)){
print(" CHECKED"); // note the space before the word
}

print(">"); // end the tag
print($checkboxvalue."<BR>"); // print the caption

// if you're going to loop, end it here