Many checkboxes in form, how do I check which ones are checked?
Expand Post »
I am making a section in the users' profile where they pick their favorite teams, which might be in different leagues (NCAA, MLB, NFL).
When the user picks the league, it takes them to the next page that lists the teams under their respective conferences (Big 10, Big 12, NFC, AFC, National League, American League, etc.)
Each team has a checkbox, so that they can pick more than one favorite team.
My dilemma is on the action page, how do I figure out which teams have been checked? Do I have to send a field containing the number of teams in the league, and then do a loop through each one to see if the current team in the loop was checked, or is there an easier way?
Re: Many checkboxes in form, how do I check which ones are checked?
To add a to buddylee's post.
Note that if a checkbox isn't checked, it will not be sent, and will therefore not be included in the $_POST array.
(May seem obvious, but there is no harm in stating the obvious )
These are simple check boxes and if the person doesn't want to sign up to anything, they don't check the box. As Atli said, this means that if they're not checked then they don't get sent to the processing script, so a helpful way of processing them if you need to use it in a MySQL table or in an email is this:
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.