Yup. This one is tearing me up. I found a lot of tutorials on this specific subject, but nothing seems to be working for me. I must be missing something which I cannot find.
I am simply trying to keep selected checkboxes checked if there is a previous error in the form. My validation is working totally fine with all fields, but I need to retain the checked boxes and I just can't solve this.
Here are the snippets I am working with:
This checks if the $data[id] isset()
<input name="seminar[]" type="checkbox" id="seminar[]"
value="
<?php
if(isset($data['id'])) {
$checked = "checked=\"checked\"";
} else {
echo "";
}
?>
" <?php echo "$checked"; ?>>
And I even checked in my html source, and this is what is showing after submission:
<input name="seminar[]" type="checkbox" id="seminar[]" value="" checked="checked">
As you can see value="" is empty!, so in my script above it should echo "", but that's not working.
As a matter of fact, when I clear the cache and reload the form all boxes are just checked!?
Can anyone see what I am doing wrong. Maybe I am turning over the wrong stones here.. Dunno, but nearly 4 hours down the drain and I'm waiving a white flag.