Jump to content


Photo

checkbox groups


  • Please log in to reply
3 replies to this topic

#1 123guy

123guy

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts

Posted 03 March 2013 - 06:24 PM

so I am forming some checkboxes in a php loop ( i am not showing the loop, but it is in a loop).  I need to be able to have multiple check box rows with multiple values.  I am doing a customer tracking system.  I need each check box to hold the Customer First, Last, and Memberid.  How can I do this using php?  I would prefer not to have to loop through an array, so if there is a way not to do that, it would be great!

 

 <input type="radio" name="CheckboxGroup" value="yes" id="CheckboxGroup1_0<?php echo $id; ?>"><input name="first" type="hidden" value="<?php echo $first; ?>"><input name="last" type="hidden" value="<?php echo $last; ?>"><input name="member" type="hidden" value="<?php echo $id; ?>">

 

 



#2 teynon

teynon

    Advanced Member

  • Members
  • PipPipPip
  • 893 posts

Posted 03 March 2013 - 08:04 PM

If you already have the data in a database, which it appears you do, since you are outputting those values to the page, then just assign the id to the checkbox and then on the next page, pull those values from the database for the checkboxes that are checked.

 

So say you have multiple groups:

<input type="checkbox" name="response[]" value="<?php echo $id;?>"> Option 1
<br />
// Next loop
<input type="checkbox" name="response[]" value="<?php echo $id;?>"> Option 2

 

Then you can loop through the values in PHP.

foreach ($_POST['response'] as $theID) {

}

Support my Kickstarter Project!
http://www.kickstart...7618755/antroid

http://www.thomaseynon.com

Vulnerabilities: http://cwe.mitre.org...x.html#Guidance - MySQL.com hacked with SQL Injection - If it happened to them, it can happen to you.


#3 123guy

123guy

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts

Posted 03 March 2013 - 08:07 PM

Would it be the same way if I decided to use a radio button instead? Or would I not use the for each?

#4 teynon

teynon

    Advanced Member

  • Members
  • PipPipPip
  • 893 posts

Posted 03 March 2013 - 08:24 PM

Yes, but you'll need to use similar radio names to make the select functionally work as they should

 

<input type="radio" name="radiobutton[0]" value="a"><br>
<input type="radio" name="radiobutton[0]" value="b"><br>
<input type="radio" name="radiobutton[1]" value="a"><br>
<input type="radio" name="radiobutton[1]" value="b"><br>

Support my Kickstarter Project!
http://www.kickstart...7618755/antroid

http://www.thomaseynon.com

Vulnerabilities: http://cwe.mitre.org...x.html#Guidance - MySQL.com hacked with SQL Injection - If it happened to them, it can happen to you.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com