14 Replies Latest reply on Apr 23, 2008 1:59 PM by brian914

    Php form mailer/Flash help

    brian914 Level 1
      I have a php form that I am using with my Flash file. It works great so far, but I would like to get confirmation from the php in the Flash file, that the info has really been sent. I think it is already sent up in the php, but I don't know how to handle it in my Flash file. The php file is attached. Do I use the echo? How would I do that? What I want, is in my Flash file to say sending, until I get then feedback from the php, and then say, sent successfully.

      Thanks a lot for any help!
        • 1. Re: Php form mailer/Flash help
          Level 7
          Yes, using echo is fine. Have a look at the LoadVars class - specifically
          the sendAndLoad method of it.

          Essentially, you'll do something like this to get your return:

          var sv = new LoadVars();
          var rv = new LoadVars();

          rv.onLoad = function(success:Boolean){
          trace(this['Status']);
          }

          sv.Name = nameTextField.text;
          sv.FromEmail = emailTextField.text;
          etc...
          sv.sendAndLoad("url of your php script", rv);

          the rv.onLoad method will then be invoked when the php script echo's back.
          If you uncomment the echo in your script, where you send back the &Status -
          you should see the text in the onLoad function.

          --
          Dave -
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Php form mailer/Flash help
            brian914 Level 1
            Dave,
            thanks a lot. I think this got me really close.

            This is what I have so far.

            var send_lv = new LoadVars();
            //send_lv.onLoad = ShowStatus;
            //send_lv.EmailType = "Quote";
            send_lv.Name = tName;
            send_lv.FromEmail = tEmail;
            send_lv.Subject = tSubject;
            send_lv.Comments = tMsg;
            send_lv.status = "";
            send_lv.sendAndLoad("php/sendContact.php",send_lv,"Post");
            this.showAlertMsg("Sending...");

            var submitListener:Object = new Object();
            submitListener.click = function(evt:Object) {
            var result_lv:LoadVars = new LoadVars();
            result_lv.onLoad = function(success:Boolean) {
            if (success) {
            this.tf_showAlertMsg.text = "Thank you for sending us an email";
            } else {
            this.tf_showAlertMsg.text = "Email did not go through";
            }
            };
            };


            It is sending but not getting the echo yet. Do I need the Post there?

            Thanks so much for the help!

            • 3. Re: Php form mailer/Flash help
              Level 7
              >> send_lv.sendAndLoad("php/sendContact.php",send_lv,"Post");

              You defined a result_lv, but are not using it? You should not have send_lv,
              send back to itself... change that above line to:

              send_lv.sendAndLoad("php/sendContact.php",result_lv);

              POST is the default, so no it's not required.


              --
              Dave -
              Head Developer
              http://www.blurredistinction.com
              Adobe Community Expert
              http://www.adobe.com/communities/experts/


              • 4. Re: Php form mailer/Flash help
                kglad Adobe Community Professional & MVP
                use result_lv as your 2nd parameter in your sendAndLoad() method.
                • 5. Re: Php form mailer/Flash help
                  brian914 Level 1
                  Mmmmhhh, I did that and now it is not working at all anymore.

                  I have this now.

                  var send_lv = new LoadVars();
                  //send_lv.onLoad = ShowStatus;
                  //send_lv.EmailType = "Quote";
                  send_lv.Name = tName;
                  send_lv.FromEmail = tEmail;
                  send_lv.Subject = tSubject;
                  send_lv.Comments = tMsg;
                  send_lv.status = "";
                  send_lv.sendAndLoad("php/sendContact.php",result_lv,"Post");
                  this.showAlertMsg("Sending...");

                  var submitListener:Object = new Object();
                  submitListener.click = function(evt:Object) {
                  var result_lv:LoadVars = new LoadVars();
                  result_lv.onLoad = function(success:Boolean) {
                  if (success) {
                  this.tf_showAlertMsg.text = "Thank you for sending us an email";
                  } else {
                  this.tf_showAlertMsg.text = "Email did not go through";
                  }
                  };
                  };

                  • 6. Re: Php form mailer/Flash help
                    Level 7
                    It doesn't work probably because you are defining result_lv within a
                    listener, which really doesn't make any sense to do. The sendAndLoad is what
                    triggers the send to go... and result_lv is not defined there. As far as I
                    can see you want to remove the submitListener, it doesn't seem to be doing
                    anything anyway.

                    So, your code would be:

                    var send_lv = new LoadVars();
                    var result_lv:LoadVars = new LoadVars();

                    result_lv.onLoad = function(success:Boolean) {
                    if (success) {
                    this.tf_showAlertMsg.text = "Thank you for sending us an email";
                    } else {
                    this.tf_showAlertMsg.text = "Email did not go through";
                    }
                    };

                    //send_lv.EmailType = "Quote";
                    send_lv.Name = tName;
                    send_lv.FromEmail = tEmail;
                    send_lv.Subject = tSubject;
                    send_lv.Comments = tMsg;
                    send_lv.status = "";
                    send_lv.sendAndLoad("php/sendContact.php",result_lv,"Post");
                    this.showAlertMsg("Sending...");



                    --
                    Dave -
                    Head Developer
                    http://www.blurredistinction.com
                    Adobe Community Expert
                    http://www.adobe.com/communities/experts/


                    • 7. Re: Php form mailer/Flash help
                      kglad Adobe Community Professional & MVP
                      maybe he has a button component that's supposed to call the submitListener.click() function. so, he should have his sendAndLoad() method in that function
                      • 8. Re: Php form mailer/Flash help
                        brian914 Level 1
                        It is all inside an ifStatment that is inside a function, which gets called by the button that send the form. Here is the full thing.

                        function validateForm(tName:String, tEmail:String, tSubject:String, tMsg:String):Void {
                        trace("validateForm was called");
                        if (tName == "" || tName == undefined) {
                        trace("tName if");
                        this.showAlertMsg("Please enter your name");
                        } else if (tEmail == "" || tEmail == undefined || tEmail.indexOf("@") == -1 || tEmail.indexOf(".") == -1) {
                        trace("Invalid email address: "+tEmail+" infexOf1: "+tEmail.indexOf("@")+" indexOf2: "+tEmail.indexOf("."));
                        this.showAlertMsg("Invalid email address");
                        } else if (tSubject == "" || tSubject == undefined) {
                        trace("tSubject if");
                        this.showAlertMsg("Please enter a subject");
                        } else if (tMsg == "" || tMsg == undefined) {
                        trace("tComments if");
                        this.showAlertMsg("Please enter some comments");
                        } else {
                        trace("the else was called...");
                        var send_lv = new LoadVars();
                        //send_lv.onLoad = ShowStatus;
                        //send_lv.EmailType = "Quote";
                        send_lv.Name = tName;
                        send_lv.FromEmail = tEmail;
                        send_lv.Subject = tSubject;
                        send_lv.Comments = tMsg;
                        send_lv.status = "";
                        send_lv.sendAndLoad("php/sendContact.php",result_lv,"Post");
                        this.showAlertMsg("Sending...");

                        var submitListener:Object = new Object();
                        submitListener.click = function(evt:Object) {
                        var result_lv:LoadVars = new LoadVars();
                        result_lv.onLoad = function(success:Boolean) {
                        if (success) {
                        this.tf_showAlertMsg.text = "Thank you for sending us an email";
                        } else {
                        this.tf_showAlertMsg.text = "Email did not go through";
                        }
                        };
                        };
                        }
                        }
                        function showAlertMsg(msg:String):Void {
                        this.tf_showAlertMsg.text = "";
                        this.tf_showAlertMsg.text = msg;
                        }

                        this.send_btn.onRelease = function() {
                        validateForm(tf_Name,tf_Email,tf_Subject,tf_Comments);
                        };


                        I tried the new way Dave posted and it still does not get the echo from the form.

                        Thanks so much to both of you for the help!


                        • 9. Re: Php form mailer/Flash help
                          kglad Adobe Community Professional & MVP
                          well, submitListener.click has to be called before your sendAndLoad executes and that isn't going to happen with your code no matter what else you're doing and not showing.

                          what's that submitListener.click supposed to do, anyway?
                          • 10. Re: Php form mailer/Flash help
                            brian914 Level 1
                            I guess that is where i am lost...

                            • 11. Re: Php form mailer/Flash help
                              kglad Adobe Community Professional & MVP
                              then follow dave's advice and remove your instantiation of result_lv and its onLoad method from that function.
                              • 12. Re: Php form mailer/Flash help
                                brian914 Level 1
                                Yeah, I tried that.

                                var send_lv = new LoadVars();
                                var result_lv:LoadVars = new LoadVars();
                                result_lv.onLoad = function(success:Boolean) {
                                if (success) {
                                this.tf_showAlertMsg.text = "Thank you for sending us an email";
                                } else {
                                this.tf_showAlertMsg.text = "Email did not go through";
                                }
                                };

                                //send_lv.EmailType = "Quote";
                                send_lv.Name = tName;
                                send_lv.FromEmail = tEmail;
                                send_lv.Subject = tSubject;
                                send_lv.Comments = tMsg;
                                send_lv.status = "";
                                send_lv.sendAndLoad("php/sendContact.php",result_lv,"Post");
                                this.showAlertMsg("Sending...");


                                But it never triggers the
                                this.tf_showAlertMsg.text = "Thank you for sending us an email";

                                The email gets sent, but it just does not report back.
                                • 13. Re: Php form mailer/Flash help
                                  kglad Adobe Community Professional & MVP
                                  put a trace(this.tf_showAlertMsg) function in your onLoad method to see if the onLoad method is being called and if your path/name to your textfield is correct.

                                  p.s. you've uncommented, at least, one of your php echo statements, correct?
                                  • 14. Re: Php form mailer/Flash help
                                    brian914 Level 1
                                    p.s. you've uncommented, at least, one of your php echo statements, correct?

                                    No, I just did that. Does it matter which one? I tried the second one and it did not change anything.

                                    ...
                                    //if($debug)
                                    // echo "mes1 $ToEmailType $ToEmail $Subject $Message From: $Name $FromEmail\n ";

                                    //mail to Eric Tillinghast
                                    mail("brian@agilitygraphics.com","website contact form - $Subject", $Message, "From: $Name <".$Email.">");

                                    //mail acknowledgement to the user
                                    //$AcknowledgementMessage = "Hello $Name.\n\n Thank you for your interest in my art. I have received your email and will respond as soon as possible.\n\nThank You, \nEric Tillinghast.\n\n\nwww.erictillinghast.info";
                                    //mail($Name."<".$Email.">", "I have received your email", $AcknowledgementMessage, "From: Eric Tillinghast <info@erictillinghast.info>");

                                    //echo "&Status=Your quote request has been sent.";
                                    ?>


                                    Ad the trace like this?
                                    result_lv.onLoad = function(success:Boolean) {
                                    trace(this.tf_showAlertMsg);
                                    if (success) {
                                    this.tf_showAlertMsg.text = "Thank you for sending us an email";
                                    } else {
                                    this.tf_showAlertMsg.text = "Email did not go through";
                                    }
                                    };


                                    Kind of confused on all this right now...
                                    Thank you for the help!