Select multi-select form from array
- by Budove
Here's the issue. I have a database column called pymnt_meth_pref, which contains a comma separated string of payment methods chosen from a multiselect form.
<td>Payment Methods Used:<br />
<input type="checkbox" name="pyment_meth_pref[]" value="Cash">I can pay with cash.<br />
<input type="checkbox" name="pyment_meth_pref[]" value="Check">I can pay by check.<br />
<input type="checkbox" name="pyment_meth_pref[]" value="Credit Card">I can pay by credit card.<br />
<input type="checkbox" name="pyment_meth_pref[]" value="Paypal">I can pay with Paypal.<br /> </td>
This array is posted to a variable and turned into a comma separated string
if (isset($_POST['pyment_meth_pref']))
$pymntmethpref = implode(", ", $_POST['pyment_meth_pref']);
if (isset($_POST['pyment_meth_acc']))
$pymntmethacc = implode(", ", $_POST['pyment_meth_acc']);
This is then inserted into the database as a comma separated string.
What I would like to do, is take this string and apply the values to the original form when the user goes back to the form as 'pre-selected' checkboxes, indicated that the user has already selected those values previously, and keeping those values in the database if they choose to edit any other information in the form.
I'm assuming this would need to be done with javascript but if there is a way to do it with PHP I'd rather do it that way.