[thelist] checked vs. unchecked checkboxes

noah noah at tookish.net
Tue Oct 19 16:46:57 CDT 2004

Mark Joslyn wrote (19/10/2004 4:49 PM):

> The only way I can return all the "successful" form controls is to have all
> of them use different names. If I use "chkIn" as the checkbox name for all
> my checkboxes, I only receive one value - the last value.
> I output the posted variable to the screen before any PHP processing was
> done on it and it is only posting one variable - the last one declared.

<tip type="Processing Checkboxes in PHP">
In order to get all of the data from a series of related checkboxes in 
PHP, you have to tell PHP that you're handing it an array by having the 
name of the checkboxes end in "[]". For example, if your form looks like 

<form action="POST">
<input type="checkbox" name="chkIn[]" value="foo" />
<input type="checkbox" name="chkIn[]" value="bar" />
<input type="submit" />

Then when the page is processed, $_POST['chkIn'] will be an array of all 
the checked boxes. If you omit the "[]", then $_POST['chkIn'] will 
contain only the value of the last checked box.


More information about the thelist mailing list