How to submit radio buttons from multiple groups?

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
lady bugg
Forum Newbie
Posts: 4
Joined: Wed Sep 24, 2008 6:00 pm

How to submit radio buttons from multiple groups?

Post by lady bugg »

I have been using radio buttons for customers to select amounts of my product inside of tables. I have over 10 different products/tables.

How can I use a single 'Submit' button at the bottom to collect data from all the groups? Each group has its own name. When I go to the action site (in this case just 1.php), I use just a simple:

echo $_POST['lavender'];

which has nothing. If I move the 'Submit' button inside of the table for lavender, I get the value I expect. Please help, here is my code so far.

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ladybug Incense</title>
<style type="text/css">
<!--
.style1 {
    font-size: 24px;
    color: #FF00FF;
}
.style2 {font-size: 24px; color: #FF0066; }
-->
</style></head>
 
<body>
<h1>Types of Incense:</h1>
<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#FFFF00"><span class="style1">Lavender</span></td>
  </tr>
  <tr>
    <td bgcolor="#00FFFF">Lavender incense is made from the finest lilac flowers, and has a hint of tulip.</td>
  </tr>
  <tr>
    <td bgcolor="#00FFFF"><form id="form1" name="form1" method="post" action="">
      <p>
        <label>
          <input type="radio" name="lavender" value="10" id="RadioGroup1_0" />
          10 grams</label>
        ($10)<br />
        <label>
          <input type="radio" name="lavender" value="18" id="RadioGroup1_1" />
          20 grams ($18)</label>
        <br />
        <label>
          <input type="radio" name="lavender" value="25" id="RadioGroup1_2" />
          30 grams ($25)</label>
        <br />
        <label>
          <input type="radio" name="lavender" value="30" id="RadioGroup1_3" />
          40 grams ($30)</label>
        <br />
      </p>
    </form>
    </td>
  </tr>
</table>
<p>&nbsp;</p>
<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#FFFF00" class="style2">Jasmine</td>
  </tr>
  <tr>
    <td bgcolor="#00FFFF">Jasmine incense is made from a variety of middle eastern flowers, mainly jasmine</td>
  </tr>
  <tr>
    <td bgcolor="#00FFFF"><form id="form2" name="form2" method="post" action="">
      <p>
        <label>
          <input type="radio" name="jasmine" value="12" id="RadioGroup2_0" />
          10 grams ($12)</label>
        <br />
        <label>
          <input type="radio" name="jasmine" value="20" id="RadioGroup2_1" />
          20 grams ($20)</label>
        <br />
        <label>
          <input type="radio" name="jasmine" value="28" id="RadioGroup2_2" />
          30 grams ($28)</label>
        <br />
        <label>
          <input type="radio" name="jasmine" value="32" id="RadioGroup2_3" />
          40 grams ($32)</label>
        <br />
      </p>
    </form>
    </td>
  </tr>
</table>
<form id="form3" name="form3" method="post" action="1.php">
  <label>
  <input type="submit" name="button" id="button" value="Submit" />
  </label>
</form> 
<p>&nbsp;</p>
</body>
</html>
 
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: How to submit radio buttons from multiple groups?

Post by califdon »

I edited your post to use [syntax=php]tags instead of [quote] tags, for easier reading.

The problem is with your <form > ... </form> tags placement. ALL the form elements ( <input...>, etc. ) must be BETWEEN the <form> and </form> tags (not just the submit button). I think if you just move what is now line 81 up to immediately after line 17, it should work properly.[/syntax]
lady bugg
Forum Newbie
Posts: 4
Joined: Wed Sep 24, 2008 6:00 pm

Re: How to submit radio buttons from multiple groups?

Post by lady bugg »

That most definitely did work. Thank you much! :D
Post Reply