Unknown amount of checkboxes to check

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Loki
Forum Commoner
Posts: 25
Joined: Wed Jun 03, 2009 9:23 pm

Unknown amount of checkboxes to check

Post by Loki »

Ok, I have a script that has to generate a form, which could have any number of checkboxes, from 1 to idfk. I want to know how I could easilly check which checkboxes are set to "on", and get their ID, when the form is submitted.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Unknown amount of checkboxes to check

Post by requinix »

Use arrays.

Code: Select all

<input type="checkbox" name="checkbox[1]">
<input type="checkbox" name="checkbox[2]">
<input type="checkbox" name="checkbox[3]">

Code: Select all

$checkboxes = array_keys($_POST["checkbox"]);
PS: to see which ones were unchecked, figure out what checkboxes were available then "subtract" the ones that were selected.
Post Reply