3 Replies Latest reply on Feb 22, 2010 10:41 AM by pbsum83

    Radio Buttons w/ Multiple Values on a PHP Form




      I have an Online Registration form with several options that each have their own prices.  I want the form results to show the name of each option the user selects, and the total of all the prices combined.  My question is how can I do that when each radio button only allows you to attach one value?  Is there a way to somehow retrieve the option name and price as two separate values?


      <input name="option" type="radio" value="Cotton - $10" />

      <input name="option" type="radio" value="Suede - $15" />

      <input name="option" type="radio" value="Leather - Black - $20" />

      <input name="option" type="radio" value="Leather - White - $20" />


      For example, if they select 'Leather - Black - $20" I want to be able to retrieve one value of "Leather - Black" and another value of "20.00" (to add to the total price) rather than simply "Leather - Black - $20" in one value.


      Any help would be greatly appreciated!  I've only had to deal with one value for each radio button in the past.





        • 1. Re: Radio Buttons w/ Multiple Values on a PHP Form
          Ben M Adobe Community Professional

          Yes you can do this.  If I were you I would eliminate the space in the value just to eliminate confusion.  Then when you process the variable use the Explode function ( http://php.net/manual/en/function.explode.php ) to separate the values in your string.  So if you eliminate the space your code would look like:


          $_POST['option'] = $option;

          $option = explode ("-",$option);

          print $option[0]; //This would print the material

          print $option[1]; //This would print the price


          The only trick is your first two options don't have a color.  So your arrays would be different.  To offset this I would recommend that you use the same format for all options and make some sort of null value if nothing will be added for one value in the array, ie: color.

          • 2. Re: Radio Buttons w/ Multiple Values on a PHP Form
            pbsum83 Level 1

            Thank you very much!  That definitely helps a lot.


            I also have one more issue pertaining to multiple values with radio buttons.  If i have a setup like below, how would I retrieve not only the category (Senor, Adult, or Youth), but find out whether they chose 'Male' or 'Female'  AND find out the price (for adding to the total)?  Is there a way I can somehow attach hidden values to each radio button for later retrieval?


            Seniors $30:

            Male (radio button)

            Female (radio button)


            Adult $50:

            Male (radio button)

            Female (radio button


            Youth $40:

            Male (radio button)

            Female (radio button)





            • 3. Re: Radio Buttons w/ Multiple Values on a PHP Form
              pbsum83 Level 1

              Anyone?  Sorry for bumping.  Just didn't want it to get lost in the shuffle.  Hoping to sort it out today if possible. Thanks!