21 Replies Latest reply on Aug 17, 2008 5:58 PM by Mendo08

    Flash email form

    Mendo08
      I am working on an email form on Flash and I got most of it done. However theres a small mistake that I cant seem to find.

      *Heres my actionscript (please check the "if" part since the problem is there):

      stop();

      var senderLoad:LoadVars = new LoadVars();
      var receiveLoad:LoadVars = new LoadVars();

      sender.onRelease = function() {
      senderLoad.Name = Name.text;
      senderLoad.Email = Email.text;
      senderLoad.Phone = Phone.text;
      senderLoad.Message = Message.text;
      senderLoad.sendAndLoad
      (" http://mainlinejerky.com/index/mainlinemail.php",receiveLoad);
      }

      receiveLoad.onLoad = function() {
      if(this.sentOk) {
      _root.gotoAndStop("success");
      }
      else {
      _root.gotoAndStop("failed");
      }
      }


      *heres my PHP:

      <?php

      $to = "mm_slider2001@yahoo.com";
      $subject = "Mainline Jerky Order";

      $headers = "From: $Email";
      $headers .= "\nReply-To: $Email";

      $message = "Name: " . $Name;
      $message .= "\nEmail: " . $Email;
      $message .= "\n\nPhone: " . $Phone;
      $message .= "\n\n\nMessage: " . $Message;


      $sentOk = mail($to, $subject, $message, $headers);

      echo "sentOk=" . $sentOk;


      ?>


      MY problem is that even when the fields are empty, one can still submit the form without playing my
      "failed" message.

      What do I need to do? What can I add to the actionscript to play my "failed" message when a field is empty?


      Thanks in advanced! Hope the info provided is helpful!
        • 1. Re: Flash email form
          kglad Adobe Community Professional & MVP
          this.sentOk is a string, not a boolean.
          • 2. Flash email form
            Mendo08 Level 1
            Ok so what do I do?

            Do I add the Boolean? I saw a video that showed me how to do this code so Im not sure what happened. If you need to see the actual form heres the link:

            http://mainlinejerky.com/email_pg.html

            Dont use th form yet!
            • 3. Re: Flash email form
              kglad Adobe Community Professional & MVP
              compare this.sentOk with "true".
              • 4. Re: Flash email form
                Mendo08 Level 1
                Sorry but I dont have a lot of actionscript knowledge.

                How do I "compare" them? is it like this [this.sentOk=true]
                You think you can show me on the code? One thing I want is for the "Failed" message to play
                if one or all fields are empty.

                Im reading some stuff on actionscript but im still not understanding it well yet. Please help . I dont have many references to use.



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

                  • 6. Re: Flash email form
                    Mendo08 Level 1
                    Ok I see
                    I will try that out and let you know what happens. The video tutorial I saw didnt mention that part, The sent.ok==true.

                    Thank you.
                    • 7. Re: Flash email form
                      Mendo08 Level 1
                      I added [this.sentOk == "true"] but I think Im still missing more. It only plays the "failed" message and still sends the email. Are you sure there isnt more I need to add to the code?
                      • 8. Re: Flash email form
                        kglad Adobe Community Professional & MVP
                        change your php script to:

                        echo "sentOk=true";
                        • 9. Re: Flash email form
                          sbryner Level 1
                          What if you checked it before you sent it like this?

                          sender.onRelease = function() {
                          senderLoad.Name = Name.text;
                          senderLoad.Email = Email.text;
                          senderLoad.Phone = Phone.text;
                          senderLoad.Message = Message.text;

                          if(senderLoad.Name==""||senderLoad.Email==""||senderLoad.Phone==""||senderLoad.Message"){
                          // throw up an alert box
                          }else{
                          senderLoad.sendAndLoad
                          (" http://mainlinejerky.com/index/mainlinemail.php",receiveLoad);
                          }
                          };
                          • 10. Flash email form
                            Mendo08 Level 1
                            Ok heres what I got so far. It worked for a while at first but now its not sending the emails.

                            actionscript:
                            stop();

                            var senderLoad:LoadVars = new LoadVars();
                            var receiveLoad:LoadVars = new LoadVars();

                            sender.onRelease = function() {
                            senderLoad.Name = Name.text;
                            senderLoad.Email = Email.text;
                            senderLoad.Phone = Phone.text;
                            senderLoad.Message = Message.text;

                            if(senderLoad.Name==""||senderLoad.Email==""||senderLoad.Phone==""||senderLoad.Message==" ") {
                            _root.gotoAndStop("failed")

                            }
                            else{
                            senderLoad.sendAndLoad(" http://mainlinejerky.com/index/mainlinemail.php", receiveLoad, "POST");
                            }
                            };


                            receiveLoad.onLoad = function() {
                            if(this.sentOk = "true") {
                            _root.gotoAndStop("success");
                            }
                            else {
                            _root.gotoAndStop("failed");
                            }
                            }

                            PHP:

                            <?php

                            $to = "mm_slider2001@yahoo.com";
                            $subject = "Mainline Jerky Order";

                            $headers = "From: $Email";
                            $headers .= "\nReply-To: $Email";

                            $message = "Name: " . $Name;
                            $message .= "\nEmail: " . $Email;
                            $message .= "\n\nPhone: " . $Phone;
                            $message .= "\n\n\nMessage: " . $Message;

                            $sentOk = mail($to, $subject, $headers, $message);

                            echo "sentOk = true" . $sentOk;


                            ?>


                            The "success" and "failed" play but now the emails ARE NOT being sent! It did work for a bit but then it stopped sending emails.

                            Did I mess up somewhere? Or do I need to add something to the button. Please help!!
                            • 11. Re: Flash email form
                              kglad Adobe Community Professional & MVP
                              :

                              • 12. Re: Flash email form
                                Mendo08 Level 1
                                Hey
                                Well it was sending emails for a short while but suddenly it stopped sending the emails. I really dont know what happened. I have a feeling that something is wrong and it may not be the actionscript or the php. Do you know if its possible that something else could cause it to stop sending emails?? I cant seem to find the problem.

                                I made a few changes to my codes. Heres my actionscript:

                                stop();

                                var senderLoad:LoadVars = new LoadVars();
                                var receiveLoad:LoadVars = new LoadVars();

                                sender.onRelease = function() {
                                senderLoad.Name = Name.text;
                                senderLoad.Email = Email.text;
                                senderLoad.Phone = Phone.text;
                                senderLoad.Message = Message.text;

                                if(senderLoad.Name==""||senderLoad.Email==""||senderLoad.Phone==""||senderLoad.Message=="" ) {
                                _root.gotoAndStop("failed")

                                }
                                else{
                                senderLoad.sendAndLoad(" http://mainlinejerky.com/index/mainlinemail.php", receiveLoad, "POST");
                                }
                                };


                                receiveLoad.onLoad = function() {
                                if(this.sentOk = "true") {
                                _root.gotoAndStop("success");

                                }
                                else {
                                _root.gotoAndStop("failed");
                                }
                                }


                                My PHP

                                <?php

                                $to = "mm_slider2001@yahoo.com";
                                $subject = "Mainline Jerky Order";

                                $headers = "From: " . $_POST['Email'];
                                $headers .= "\nReply-To: " . $_POST['Email'];

                                $message = "Name: " . $_POST['Name'];
                                $message .= "\nEmail: " . $_POST['Email'];
                                $message .= "\n\nPhone: " . $_POST['Phone'];
                                $message .= "\n\n\nMessage: " . $_POST['Message'];

                                $sendOk = mail($to, $subject, $headers, $message);

                                echo "sentOk=true";


                                ?>

                                Im thinking its my PHP that may be wrong or may be corrupted, I dont know! MAybe Im missing something now. Well if you could take a look that would be awsome. Doing this idoesnt seem very difficult but for some reason Im having a hard time getting this to work the way I want.

                                Please help! thanks!!
                                • 13. Re: Flash email form
                                  kglad Adobe Community Professional & MVP
                                  i don't see anything wrong with the code you posted. but you should be using a relative path to your php file because your hosting company may have restrictions on what could appear to be an outside call to an executable file and you should use the receiveLoad.onData(src) and view the returned src parameter. the latter may show error messages being generated.
                                  • 14. Flash email form
                                    Mendo08 Level 1
                                    what would you consider to be a "relative path"?

                                    and is th this what you mean for "onData"?

                                    receiveLoad.onData = function() {
                                    if(this.sentOk = "true") {
                                    _root.gotoAndStop("success");

                                    Please show me on the code cuz it seemed like I understood this but its like I dont quite get it anymore!

                                    I'll contact my hosting company askin them about my php. file


                                    thanks!
                                    • 15. Re: Flash email form
                                      kglad Adobe Community Professional & MVP
                                      if you have flash tracer installed you can use:

                                      • 16. Flash email form
                                        Shandy Elliott Level 1
                                        Maybe this can help. I used your variables, instance names, and frame references as much as I could so you can apply this to your document. I created a fla and php for you. You can download the files at http://www.shan-dysigns.com/flash/mainlineEmail/mainlineEmail.zip to see what I did. You can test what I've done at http://www.shan-dysigns.com/flash/mainlineEmail/mainlineEmail.swf - it worked when I replaced my email address for your email address in the php file, so unless my server has a problem with a foreign email address crossing this path (as it can some times), this should work and show you how I did it.

                                        I know this post was getting long, so I thought I could create a working example for you and you can see what I did and apply it. Let me know if this helps at all.

                                        EDIT: Make sure you upload the swf and php file to your server space to test any changes you make. I also should add in the php script, there is an option to send an "auto reply" to the person who fills out the form. I think this would come in handy in your case.
                                        • 17. Flash email form
                                          Mendo08 Level 1
                                          Shan-Dysigns

                                          Just wanna say THANK YOU SO VERY MUCH! YOU ARE A SAVIOR!!
                                          Guess it was my php script but I just cant seem to find the problem! What was it!?

                                          Now while it works now thanks to your php script, I have a small problem which i think can be fixed. On you actionscript you have this:

                                          http://www.shan-dysigns.com/flash/mainlineEmail/mainlineEmail.php

                                          I uploaded my php script (which is actually what you wrote but now modified to fit my form) but I dont know what the appropriate way to upload it is. Do you have yours in folders or what?

                                          The reason...once I uploaded my form to my website it doesnt send the email and I think its because it cant find the script.

                                          Please help.

                                          Thanks!!!
                                          • 18. Re: Flash email form
                                            Shandy Elliott Level 1
                                            Your script seems to have changed a couple of times in this post, so I would have to know the particular problem you were having compared to the script you were using at that time. I think it's just easier to look at what I did, compare it yours, and notice the differences.

                                            "I uploaded my php script (which is actually what you wrote but now modified to fit my form) but I dont know what the appropriate way to upload it is. Do you have yours in folders or what?" - Just make sure the path to the php script in your action script reflects the path to the file on your server. I always place the php file in the same folder as my swf file (which are always placed under the root folder of the web server). You can place the php file in a different folder than your swf file - just make sure you have the correct path in your script. I always use absolute paths in my script when it comes to connecting to files other than swf files (my choice).

                                            It's possible you have a "scope" problem with your variables. If you are trying passing empty or undefined variables, the php script will fail. Comment out the sendAndLoad line of script (place "//" in front of the script) and add a trace:

                                            trace (Name.text+newline+Email.text+newline+Phone.text+newline+Message.text);

                                            Test that in Flash to see if it traces the same values as when you fill out the form. How do you know it's not sending the email (other than you not receiving it)? Are you testing this by putting your email address in the Email field?

                                            If you are still having trouble, I will need to see your fla file and your edited php file to help further.
                                            • 19. Flash email form
                                              Mendo08 Level 1
                                              ok heres what i did, just to see that I wasnt crazy. I uploaded you swf and your PHP into my server and the flash form is in my contact pg. The only change was the path of the php file in the actionscript. everything else is the same when I got the zip file from you. check it:

                                              http://mainlinejerky.com/email_pg.html

                                              and it ONLY works when I exported from flash but it wont work after uploading it into my server. Same thing with my version. Go ahead and try it.

                                              in my actionscript i typed:
                                              http://www.mainlinejerky.com/index/mainlineEmail.php

                                              since thats the location of the script. Its under the "index" folder in my server. So what would be the correct way to describe the location or "Path" of the PHP? feel free to use the form.

                                              Thanks for your time!!
                                              • 20. Re: Flash email form
                                                Shandy Elliott Level 1
                                                I noticed you have placed a lot of content in this "index" folder (viewing your page source). Did you create this folder? It's obviously not the root of your web server because the index.html page of http://mainlinejerky.com/index.html is at the root of your server. I see that email_pg.html is at the root which holds the swf file at index/mainlineEmail.swf. You said you placed the php script at the same level as the swf index/mainlineEmail.php.

                                                In the distant past, I've come across some servers where the php scripts will ONLY work at the root level of the server. Because of that possibility, I always place my swf files and script files at the root level of my clients' server. You can test this out by uploading the swf file and php script to the root of your web server (same area where index.html lies). If you notice my example I sent a few posts ago, I had several folder levels to that script -

                                                "flash/mainlineEmail/mainlineEmail.php" - the swf file is at the same level. So, by placing those 2 files at the root of your server will be a good test. If things worked (my example) when you exported from Flash but not when you uploaded, try switching the absolute path to a relative one. Actually, try this first before you upload the php file and swf to the root of your server. So, your sendAndLoad would point to "mainlineEmail.php" - if that doesn't change anything, try the other suggestion of uploading to the root of your web server.

                                                So, to clear things up, try:

                                                1. change your absolute path to a relative one, publish flash file, re-upload the swf file to index/mainlineEmail.swf - test it
                                                2. upload mainlineEmail.swf and mainlineEmail.php to the root of your web server - test it

                                                If neither one of those pass, there may be something else in your flash file that's causing the conflict. I can help a lot faster if I can see the flash file and the php script you are currently using.
                                                • 21. Re: Flash email form
                                                  Mendo08 Level 1
                                                  Hey friend!
                                                  Your tip worked!!! Oh man I finally got it to work right! I never thought this would be so hard to figure out! Man thank you sooooo very much for your time. I guess actionscript and php isnt as easy to understand as it looked.

                                                  Again you are a SAVIOR!!!

                                                  God Bless you!!