12 Replies Latest reply on Sep 14, 2009 1:53 PM by kglad

    contact form

    phatmike10

      Hi,

       

      I’ve found a tutorial for a form which has a dynamic text box in it and would be perfect for my site. I followed the tutorial step by step but when I click the submit button, all that happens is ‘undefined’ appears in the dynamic box. The validation seems to work though. The tutorial isn’t very long and its really annoying me. Please could you have a look at the tutorial and explain to me why it doesn’t work? It’s at www.flashkid.org/Tutorials/flash_contact_form.html

      Thank you very much

       

      Mike

        • 1. Re: contact form
          kglad Adobe Community Professional & MVP

          do you have server-side code?

          • 2. Re: contact form
            phatmike10 Level 1

            yes, i used the exact php code that's at the bottom of the tutorial.

            • 3. Re: contact form
              kglad Adobe Community Professional & MVP

              show your actionscript code.

              • 4. Re: contact form
                phatmike10 Level 1

                Note: frame 1 actionscript:

                 

                serverFile = "mail.php";

                stop();

                //function to seperate form validation checks from email sending logic
                function formValidationChecks(){
                //checking if email format is valid
                if ((!email.text.length) || (email.text.indexOf("@") == -1) || (email.text.indexOf(".") == -1)) {
                  status.text = "Please enter a valid E-mail address";
                  return false;
                //checking if from field is not blank
                } else if (!from.text.length) {
                  status.text = "Please enter Your Name";
                  return false;
                //checking if message is not blank
                } else if (!message.text.length) {
                  status.text = "Please Enter Your Message";
                  return false;
                }
                return true; //returning success if everything is fine
                }

                 

                 

                Note: submit button action script:

                 


                on (release) {
                status.text = ""; //clearing status field for this attempt

                if(formValidationChecks()){ //calls function and validate form inputs
                 
                  //creating two LoadVars objects, to send and receive values (see flash help)
                  my_lv = new LoadVars();
                  result_lv = new LoadVars();
                 
                  //filling first object with form values
                  my_lv.from = from.text;
                  my_lv.email = email.text;
                  my_lv.message = message.text;

                  //tracing out to make sure right values are sent
                  trace( my_lv.from + " " + my_lv.email + " " + my_lv.message);
                 
                  //line that sends variables to mail.php file (severFile variable)
                  my_lv.sendAndLoad(serverFile, result_lv, "POST");
                 
                  //event which is called when result_lv passed above, receives response from php page
                  result_lv.onLoad = function(success:Boolean) {
                   if (success) {
                    from.text = email.text = message.text = "";   //clearing all fields
                   }
                   status.text = result_lv ["serverResponse"];   //entering response to status field for display
                  }; //end of onLoad event
                }
                }//end of button event

                 

                 

                php code:

                 

                <?php

                $from    = $_REQUEST["from"];
                $email   = $_REQUEST["email"];
                $message = $_REQUEST["message"];

                $to          = stu@rvpuk.com;
                $subject  = "Enquiry";
                $full_msg = "From Name: " . $from . "\n From Email: " .  $email .  "\n Message: " . $message;

                $ok= mail($to, $subject, $full_msg);

                            if($ok) {
                                        echo( "&serverResponse=The mail was successfully sent");
                            } else {
                                        echo("&serverResponse=Sorry but the email could not be sent. Please try again!");
                            }

                ?>

                • 5. Re: contact form
                  kglad Adobe Community Professional & MVP

                  use the following and report what's traced:

                   


                   

                  serverFile = "mail.php";

                  stop();

                  //function to seperate form validation checks from email sending logic
                  function formValidationChecks(){
                  //checking if email format is valid
                  if ((!email.text.length) || (email.text.indexOf("@") == -1) || (email.text.indexOf(".") == -1)) {
                    status.text = "Please enter a valid E-mail address";
                    return false;
                  //checking if from field is not blank
                  } else if (!from.text.length) {
                    status.text = "Please enter Your Name";
                    return false;
                  //checking if message is not blank
                  } else if (!message.text.length) {
                    status.text = "Please Enter Your Message";
                    return false;
                  }
                  return true; //returning success if everything is fine
                  }

                   

                   

                  assign your button an instance name (say submitBtn) and attached to the frame that contains your button:

                   

                    my_lv = new LoadVars();
                    result_lv = new LoadVars();
                   
                    //filling first object with form values
                    my_lv.from = from.text;
                    my_lv.email = email.text;
                    my_lv.message = message.text;

                   
                    //event which is called when result_lv passed above, receives response from php page
                    result_lv.onData = function(src) {
                  trace(src);
                    }

                   


                  submitBtn.onRelease=function(){
                  status.text = ""; //clearing status field for this attempt

                  if(formValidationChecks()){

                    my_lv.sendAndLoad(serverFile, result_lv, "POST");

                  }
                  }//end of button event

                   

                   

                  php code:

                   

                  <?php

                  $from    = $_REQUEST["from"];
                  $email   = $_REQUEST["email"];
                  $message = $_REQUEST["message"];

                  $to          = stu@rvpuk.com;
                  $subject  = "Enquiry";
                  $full_msg = "From Name: " . $from . "\n From Email: " .  $email .  "\n Message: " . $message;

                  $ok= mail($to, $subject, $full_msg);

                              if($ok) {
                                          echo( "&serverResponse=The mail was successfully sent");
                              } else {
                                          echo("&serverResponse=Sorry but the email could not be sent. Please try again!");
                              }

                  ?>

                  • 6. Re: contact form
                    phatmike10 Level 1

                    I deleted the code that was previously attached to the button and replaced it with the following but when I validated it, there were loads of errors:

                     

                    my_lv = new LoadVars();

                    result_lv = new LoadVars();
                     
                    //filling first object with form values
                    my_lv.from = from.text;
                    my_lv.email = email.text;

                    my_lv.message = message.text;

                     
                    //event which is called when result_lv passed above, receives response from php page
                    result_lv.onData = function(src) {
                    trace(src);
                    }

                     

                    submitBtn.onRelease=function(){
                    status.text = ""; //clearing status field for this attempt

                     

                     

                    if(formValidationChecks()){

                    my_lv.sendAndLoad(serverFile, result_lv, "POST");

                    }
                    }//end of button event

                    • 7. Re: contact form
                      phatmike10 Level 1

                      i've just tried uploading all the files onto a different server to see what would happen (using exactly the same original code) and instead of getting 'undefined' appearing in the dynamic text box, I get a message in my dynamic text box from a line in my php code: echo("&serverResponse=Sorry but the email could not be sent. Please try again!");

                      • 8. Re: contact form
                        kglad Adobe Community Professional & MVP

                        now use the trace function to make sure you're sending the variables you think you are sending.

                        • 9. Re: contact form
                          phatmike10 Level 1

                          Hi, sorry its taken me so long to get back to you.

                           

                          I'm not quite understanding where your trace function goes, I understtod it as follows (which didn't produce any errors or a message in the status box):

                           

                           

                          on (release) {
                          status.text = ""; //clearing status field for this attempt

                          if(formValidationChecks()){ //calls function and validate form inputs
                           
                            //creating two LoadVars objects, to send and receive values (see flash help)
                            my_lv = new LoadVars();
                            result_lv = new LoadVars();
                           
                            //filling first object with form values
                            my_lv.from = from.text;
                            my_lv.email = email.text;
                            my_lv.message = message.text;

                          //event which is called when result_lv passed above, receives response from php page
                            result_lv.onData = function(src) {
                          trace(src);
                            }

                           

                          submitBtn.onRelease=function(){
                          status.text = ""; //clearing status field for this attempt

                          if(formValidationChecks()){

                            my_lv.sendAndLoad(serverFile, result_lv, "POST");

                          }
                          }}}//end of button event

                          • 10. Re: contact form
                            kglad Adobe Community Professional & MVP

                            what's the output from:

                             

                            phatmike10 wrote:

                             

                            Hi, sorry its taken me so long to get back to you.

                             

                            I'm not quite understanding where your trace function goes, I understtod it as follows (which didn't produce any errors or a message in the status box):

                             

                             

                            on (release) {
                            status.text = ""; //clearing status field for this attempt

                            if(formValidationChecks()){ //calls function and validate form inputs
                             
                              //creating two LoadVars objects, to send and receive values (see flash help)
                              my_lv = new LoadVars();
                              result_lv = new LoadVars();
                             
                              //filling first object with form values
                              my_lv.from = from.text;
                              my_lv.email = email.text;
                              my_lv.message = message.text;

                            trace(from.text+" "+email.text+" "+message.text);

                            //event which is called when result_lv passed above, receives response from php page
                              result_lv.onData = function(src) {
                            trace(src);
                              }

                             

                            submitBtn.onRelease=function(){
                            status.text = ""; //clearing status field for this attempt

                            if(formValidationChecks()){

                              my_lv.sendAndLoad(serverFile, result_lv, "POST");

                            }
                            }}}//end of button event

                            • 11. Re: contact form
                              phatmike10 Level 1

                              sorry, i'm not sure what you mean?

                              • 12. Re: contact form
                                kglad Adobe Community Professional & MVP

                                if you can't run that locally, and don't have the ability to see trace() output in your browser, for testing create and assign two textfields to display that text and src.