[thelist] php: how to reselect a checkbox on page reload

Dunstan Orchard dunstan at 1976design.com
Sat Aug 9 08:28:51 CDT 2003

Hi there,

I don't know if it's the heat, or that I haven't done any PHP for a while, but 
I'm unable to figure this one out:

I have a form. The form contains a series of checkboxes. The form also 
contains a number of compulsory fields. If the user fails to fill out these 
compulsory fields then the page reloads with an error message and the user's 
previously entered data still intact.

I'm stuck on how to re-select the checkboxes that the user had chosen before 
hitting submit.

I can do it on a case-by-case basis, but I'd rather use a little function.

Can anyone suggest a solution? I'm sure it involves arrays, it always does.

Here's a simplified snippet from the code:

<input type="checkbox" name="cat[]" id="bandc_cat" value="Barrel and Container 
Pumps" /> Barrel and Container Pumps<br />
<input type="checkbox" name="cat[]" id="lab_cat" value="Laboratory Pumps" /> 
Laboratory Pumpsbr />
<input type="checkbox" name="cat[]" id="sanit_cat" value="Sanitary Pumps" /> 
Sanitary Pumps

Many thanks,

- Dunstan

Dorset, England

More information about the thelist mailing list