I want to do this so that the user can be returned to the form in the case of an error and still have all the checkboxes still check from before they submitted a form.
The way I thought of doing this was to place all the data in the SESSION array. This works easily for the text fields, but the multiple checkboxes have been a problem.
Here's what I've got:
<?php
function findit($s)
{
$arr = $_SESSION['statevisited'];
$states_string = implode(",", $arr);
$pos = strpos($states_string, $s);
if ($pos !== false)
{
echo 'checked="true"';
}
}
?>
<input type="checkbox" name="statevisited[]" value="Alabama" <?php findit('Alabama') ?> >Alabama<br/>
[...etc...the rest of 50 states...]
I'm trying to call the function from within the <input> tag in hopes of returning the checked="true" attribute if the findit function finds the passed state name in the SESSION array.
This is not working. It doesn't seem that I can call a function from here. I've tested calling the function from else where with no problems. But it doesn't work from inside the tag.
Perhaps I'm going about this all wrong.