Forms with Multiple Checkbox Arrays

When I’m making web forms I can never remember exactly how to set “stuff” up.  I’m thinking I’m probably not the only one with this leaky brain problem.  Anyway, I was setting up a pretty large form today and had to create a group of check boxes.  When you’re doing a checkbox group and actually need to be able to see all of the checkboxes that were checked so you can save the info to a database, you have to jump through a couple hoops. First of all, here’s what you get when you do a search for “checkbox group html” in Google.

That seems right, right?  Just name each checkbox in the group the same thing, and you’re good to go.  The problem is that when you try to read those values in PHP, all you get is the last one (value3, in this case). To get all three values, you need to make the checkboxes part of an array, like this.

Then, when you need to get the values, you just step through the array, like any other array.

Pretty simple.  Just thought I would share so maybe it helps someone else.    

Leave a Reply

Your email address will not be published. Required fields are marked *