Multiple check boxs

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
petethepirate
Forum Newbie
Posts: 10
Joined: Sat Oct 04, 2008 5:33 pm

Multiple check boxs

Post by petethepirate »

I cant figure this one out. I need mutiple check boxes (form submit) for each item, not just one check box. For example, lets say I list out fruit items at a grocery store. For each item I have a check box for BUY, INSPECT, and SMELL. I can check one, two, all three, or none at all. Anyone know how to do this? Thanks.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Multiple check boxs

Post by califdon »

petethepirate wrote:I cant figure this one out. I need mutiple check boxes (form submit) for each item, not just one check box. For example, lets say I list out fruit items at a grocery store. For each item I have a check box for BUY, INSPECT, and SMELL. I can check one, two, all three, or none at all. Anyone know how to do this? Thanks.
Unless I don't understand what you want to do, just give each checkbox a different name. What are you doing with the data?
petethepirate
Forum Newbie
Posts: 10
Joined: Sat Oct 04, 2008 5:33 pm

Re: Multiple check boxs

Post by petethepirate »

I am giving them different names. Lets say someone clicks two different check boxs on line 2, all it returns is ON for line 2. Im trying to get 3 different values from each line.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Multiple check boxs

Post by califdon »

petethepirate wrote:I am giving them different names. Lets say someone clicks two different check boxs on line 2, all it returns is ON for line 2. Im trying to get 3 different values from each line.
I can't visualize what you mean. Show us the code for your Form (please enclose php code in bracketed php tags for readability--that is, use the Code button on the message input screen, and change the "text" to "php" if it's php code).
User avatar
omika
Forum Newbie
Posts: 19
Joined: Sun Oct 12, 2008 2:00 pm
Location: New Zealand

Re: Multiple check boxs

Post by omika »

So its like

Apple: []Buy
[]Inspect
[]Smell

Pear: []Buy
[]Inspect
[]Smell

Code: Select all

<?php
                           
         echo "Apple: <input type='checkbox' name='apple[]' value='Buy'>Buy<br>
                             <input type='checkbox' name='apple[]' value='Inspect'>Inspect<br>
                             <input type='checkbox' name='apple[]' value='Smell'>Smell<br><br>";
 
         echo "Pear: <input type='checkbox' name='pear[]' value='Buy'>Buy<br>
                             <input type='checkbox' name='pear[]' value='Inspect'>Inspect<br>
                             <input type='checkbox' name='pear[]' value='Smell'>Smell<br><br>";
?>
Lets say Apple has buy and smell selected, an array called apple now contains Buy and Smell. When you post you can do whatever with the array eg.

Code: Select all

<?php
 
$applestuff = implode(', ', $_POST['apple']); //Converts an array into a single string 
echo $applestuff; //Output: Buy, Smell
?>
petethepirate
Forum Newbie
Posts: 10
Joined: Sat Oct 04, 2008 5:33 pm

Re: Multiple check boxs

Post by petethepirate »

Thanks!
Post Reply