[thelist] checked vs. unchecked checkboxes

Paul Bennett paul at web-business-pack.com
Tue Oct 19 16:58:11 CDT 2004

thanks Noah - I remember having this exact problem about a year ago and 
couldn't remember what was done to solve it - although I knew it was 
something client side...

noah wrote:

> 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 (simplified):
> <form action="POST">
> <input type="checkbox" name="chkIn[]" value="foo" />
> <input type="checkbox" name="chkIn[]" value="bar" />
> <input type="submit" />
> </form>
> 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.
> </tip>
> Cheers,
> Noah

More information about the thelist mailing list