11 Replies Latest reply on Nov 12, 2007 9:39 AM by Dave Blake

    Passing Radio button variables

    Dave Blake Level 1
      I am trying to figure out how to pass the variables of a radio button group in an email form. I have been going through everything I can find and tried a number of approaches with no success. I am able to pass text field information with no problem but I get a "[object Object]" result for my radio buttons. I am using PHP to process the email form.

      I have two radio buttons in a group named "Softwaresupply". From what I understand, I need to load the variables of the resulted selection of these two radio buttons that can then be passed to the PHP page. In my actionscript I have this set up to gather that info (why is it that you don't need to do this for the textfield info??):

      function POST() {
      formData = new LoadVars();
      formData.Softwaresupply = "";

      formData.Softwaresupply = Softwaresupply.getValue();
      }

      My submit button has the following code attached to it:
      on (release) {
      loadVariablesNum("quote.php", 0, "POST");
      Softwaresupply = formData.Softwaresupply;
      gotoAndStop(5);
      }

      The gotoandstop is simply a "thankyou for your submission screen"

      My PHP to display the results is as follows: (This includes the textfield info which does work):

      $message.="Name: ".$_POST['FirstName']." ".$_POST['LastName'];
      $message.="\nEmail: ".$_POST['Email'];
      $message.="\nPhone: ".$_POST['Phone'];
      $message.="\nPurpose: ".$_POST['Purpose'];
      $message.="\nSoftware Supply: ".$_POST['Softwaresupply'];

      SOOOO... what am I missing here???

      Thanks,
      Dave
        • 1. Re: Passing Radio button variables
          kglad Adobe Community Professional & MVP
          use the selectedData property of your radiogroup.
          • 2. Re: Passing Radio button variables
            Dave Blake Level 1
            I guess I'm not sure what you mean. Sorry.
            • 3. Re: Passing Radio button variables
              kglad Adobe Community Professional & MVP
              if your radio group name is Softwaresupply and they are on the same timeline as your button and your button is a true button, you can use:

              • 4. Re: Passing Radio button variables
                Dave Blake Level 1
                Well I revised the coding based on your suggestions to the following:

                Code on actions timeline:
                stop();


                function POST() {
                formData = new LoadVars();
                formData.Softwaresupply = "";

                formData.Softwaresupply = Softwaresupply.getValue();
                }

                Code attached to submit button:

                on (release) {
                _level0.SoftwaresupplyVar =Softwaresupply.selectedData;
                loadVariablesNum("quote.php", 0, "POST");
                gotoAndStop(5);
                }

                The radio button group is on the same frame on the timeline as the submit button.

                For the PHP form,

                I set it up as follows:
                $mesage = '';
                $message.="Name: ".$_POST['FirstName']." ".$_POST['LastName'];
                $message.="\nEmail: ".$_POST['Email'];
                $message.="\nPhone: ".$_POST['Phone'];
                $message.="\nPurpose: ".$_POST['Purpose'];
                $message.="\nSoftware Supply: ".$_POST['SoftwaresupplyVar'];

                Previously I would get "[object Object]" as a result for the Softwaresupply, now I get nothing.

                • 5. Re: Passing Radio button variables
                  kglad Adobe Community Professional & MVP
                  do your radio buttons have a data property?

                  (and are you using that loadvars for anything?)
                  • 6. Re: Passing Radio button variables
                    Dave Blake Level 1
                    Currently the data property is empty for the buttons.
                    • 7. Re: Passing Radio button variables
                      Dave Blake Level 1
                      Maybe I need to step back and make sure I understand the basic components and series of events that take place with collecting and sending data from a radio button group.

                      FIrst the radio buttons are contained within a group so that only one of the buttons can be selected- hence one value gathered. Second, each button contains a value, stored in the label field for that button.

                      Now is the point that I think I am getting confused with. Is it correct that there needs to be "listener" and "event handler" in the actionscript that "listen" for that button to be clicked and then the event handler knows to go out and gather the information of that button? From there, the information gathered is then stored in the variable. The submit button then creates the function of sending out the information contained in that variable to be processed by the php page.

                      • 8. Re: Passing Radio button variables
                        kglad Adobe Community Professional & MVP
                        no, you don't need a listener for your purposes. but if there's no data for your radio buttons what is that you want to send? their labels? if yes, use the radiogroup's selection.label property.
                        • 9. Re: Passing Radio button variables
                          Dave Blake Level 1
                          I will give this a try and get back to you! It won't be until Monday though as I'm out of the office till then.

                          Thanks,
                          Dave
                          • 10. Re: Passing Radio button variables
                            kglad Adobe Community Professional & MVP
                            you're welcome.
                            • 11. Re: Passing Radio button variables
                              Dave Blake Level 1
                              Okay-

                              That didn't work either. So I am just trying to see if I am actually collecting a variable that can be passed on. I searched around and found a sample script in which you select a radio button option and it will then display the label value in a dynamic textbox on that frame. That works for me, but if I move the dynamic textbox to a different frame, it displays the "undefined" message in the box. Here is my code on the frame with the radio button options in which the dynamic textbox is located on the same frame and works:

                              // create a listener object for the submit button
                              submitButtonListener = new Object();

                              // submit button listener, click handler method
                              submitButtonListener.click = function ()
                              {
                              // find the selected radio button in the group
                              var selectedRadioButton = Softwaresupply.selection;

                              // store the label of the selected radio button
                              var selectedRadioButtonLabel = selectedRadioButton.label;

                              // compose and display the message
                              quest.text = "You would like a " + selectedRadioButtonLabel;
                              }

                              // make the submit button listener listen for click events
                              submit.addEventListener("click", submitButtonListener);


                              Now here is how I revised the code to put the dynamic textbox on frame 5 to display the results:

                              stop() ;


                              // create a listener object for the submit button
                              submitButtonListener = new Object();

                              // submit button listener, click handler method
                              submitButtonListener.click = function ()
                              {
                              // find the selected radio button in the group
                              var selectedRadioButton = Softwaresupply.selection;

                              // store the label of the selected radio button
                              var selectedRadioButtonLabel = selectedRadioButton.label;

                              // compose and display the message
                              gotoAndStop(5);
                              }

                              // make the submit button listener listen for click events
                              submit.addEventListener("click", submitButtonListener);

                              And here is the code on frame 5:
                              stop();
                              quest.text = "You would like a " + selectedRadioButtonLabel;

                              Sigh...