lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at
PHP: HTML Form Arrays
I've done this before... but I forgot how. So here's a reminder I hope will stick with me. To process a form array for something like, say, a checklist, give all the form elements the same name with brackets attached, something like so:

<input type="checkbox" name="CHECKBOX[]" value="1" />
<input type="checkbox" name="CHECKBOX[]" value="2" />
<input type="checkbox" name="CHECKBOX[]" value="3" />
<input type="checkbox" name="CHECKBOX[]" value="4" />

Then, when the form is submitted, to process the array, you can use the $_POST global, something like this:

$CHECKBOX = array();
foreach ( $CHECKBOX as $_value )
// do something

I'll work up a working example using javascript or something when I have a chance.