Checkbox group

4 replies
Joined: 01/11/2007
User offline. Last seen 1 year 49 weeks ago.

Is there a way to set up a group of checkboxes with the same name and have formmail.php return all the values that are checked associated with the one name? Right now it seems like it will only return the last option checked if multiple checkboxes with the same name are selected. For now, I'm giving each checkbox its own name, but it'd be nice to see it be able to take muliple checkboxes and hand them all off, i.e:

What pets do you own?
[x] cat
[x] dog
[ ] snake
[ ] Billy
[x] fish
[x] goat
[x] wife
----------------------------
Pets: cat, dog, fish, goat, wife

Instead, it just returns:
Pets: wife

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 06/04/2007
User offline. Last seen 12 hours 33 min ago.

You'll need to rename the name of your input (checkbox) to use []'s.

http://www.boaddrink.com/projects/phpformmail/readme.htm#multiple

-Andrew Riley

Anonymous

Sorry for being too dumb but i can't seem to put the right codes. Can you give me an example of the actual codes for the checkboxes and where should i insert those []'s!? Thanks T_T

Joined: 11/21/2008
User offline. Last seen 3 weeks 4 days ago.

In case you haven't found an answer yet...

In your form, you'll have your checkboxes look like this:

input type="checkbox" name="type" value="Whatever"
input type="checkbox" name="type" value="Something else"

What he's saying to do is put []'s in the names. IE:

input type="checkbox" name="type[]" value="Whatever"
input type="checkbox" name="type[]" value="Something else"

And then it will work correctly. :)

Joined: 01/11/2007
User offline. Last seen 1 year 49 weeks ago.

That is beautiful, thanks!

User login