I have a form with 3 checkboxes in html: Chicago, SF, NYC.
A user can check off any of those checkboxes. The data then gets sent to my database, and I implode the data such that it is stored as individual values rather than an array.
$locationpref = implode(", ",$_POST['locationpref']);
When I refresh my page, I would like for my form to precheck the checkboxes that the user has already selected. For example, if I select Chicago and SF as my preferences, anytime I log in to my profile I would like to see those boxes checked off.
I understand the html behind it, but since the implode converts the array to a string, I cannot figure out how to search the string for "SF" or "Chicago" and then trigger the echo function accordingly.
<?php if (in_array("SF", $locationpref)) {echo "checked='checked'";} ?>
Any advice?
Thanks!
Aucun commentaire:
Enregistrer un commentaire