Jump to content

checkbox groups


123guy

Recommended Posts

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; ?>">

 

 

Link to comment
Share on other sites

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) {

}
Link to comment
Share on other sites

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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.