Topic: pre-populating checkboxes from a form submitted to itself
Hi folks, I'm hoping someone can help me understand arrays created from checkboxes in a form.
I'd like to have a user submit a form which has some checkboxes...and then have the checkboxes be pre-populated based on what the user selected (and allow the user to make changes etc. the next time it's loaded)
So, let's suppose I have some code like the following (where eventually I'll set a variable coding for "checked" to be in the form corresponding to values stored in the array $option):
$option=$_POST['option'];
echo "Value stored in \$option[red] is: ".$option[red];
echo "Value stored in \$option[blue] is: ".$option[blue];
echo "Value stored in \$option[yellow] is: ".$option[yellow];
<form action="thispage.php" method="post">
Option(s):
<ul><li><input type="checkbox" name=option[red] value="red" >Red </input>
<li><input type="checkbox" name=option[blue] value="blue">Blue </input>
<li><input type="checkbox" name=option[yellow] value="yellow">Yellow </input>
</ul>
<input type="submit" value="Submit">
</form>
What is the correct syntax to have the posted array stored in a new array? (like "red" stored in option[red] if it was selected etc.) I can't seem to implement anything correctly that I've searched and found so far.
Anyway, I know the above code is likely way off the mark but any help is greatly appreciated.