29 Replies Latest reply on Feb 22, 2007 11:49 AM by SymTsb

    getting PHP to communicate with FLASH

    em_shomer
      Im having some issues getting my flash contact form to communicate with my form.PHP I have been scouring tutorials but im just not getting what exactly goes into the PHP file. My variables are different from the tutorials I have seen. This is what I have

      I guess my main question is how do I set up the PHP file so that it can work with my flash files?
        • 1. Re: getting PHP to communicate with FLASH
          Level 7
          em_shomer wrote:
          > I guess my main question is how do I set up the PHP file so that it can work
          > with my flash files?

          Go to my site at http://foundationphp.com/flash/index.php

          Download the free sample chapter. It covers exactly what you're looking for.

          --
          David Powers, Adobe Community Expert
          Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
          Author, "PHP Solutions" (friends of ED)
          http://foundationphp.com/
          • 2. Re: getting PHP to communicate with FLASH
            em_shomer Level 1
            I dont have the book or software so I am doing this on my main project:
            I basically cut and pasted the code to frame 1 because I dont have a load date variable so everything resides on Frame 1

            I get several output errors:

            ***ERROR*** frame 1 line 2 ' { ' expected
            function checkForm() :Boolean {

            **ERROR** frame=1 line 26:
            unexpected ' } ' encountered
            }

            how do I handle this so I dont get these error messages

            • 3. Re: getting PHP to communicate with FLASH
              SymTsb Level 2
              Below is my contact form code. It works beautifully. You may have to modify it some to achieve your ultimate goal but it is very simple and easy to understand.

              • 4. Re: getting PHP to communicate with FLASH
                em_shomer Level 1
                Ok im beyond frusterated here nothing seems to be working. I have gone back to my originial contact form:
                I need help because I have been doing this for 8 hours straight and its not working Since im following several tutorials can someone explain to me by looking at my code,

                !) What is my Variable? (is it visitor_comments or userMessage.text?) are variables the same as Instance names because in this case the instance name is userMessage
                2) How do I define the Variables since i obviously havent defined it or else it would be working?
                3 How do i denote the variables in PHP

                I know i am probably making this harder than it is, but im such a noob and I dont have time to learn actionscript and PHP
                • 5. Re: getting PHP to communicate with FLASH
                  kglad Adobe Community Professional & MVP
                  noone can help you unless they are familiar with that php script or they are willing to check that php script or you inform us what variables it expects.

                  because it doesn't look like anyone is doing the first two why don't you tell us. almost certainly it is spelled out in the comments of that php script, at it beginning, what variables it needs. what are they?
                  • 6. Re: getting PHP to communicate with FLASH
                    SymTsb Level 2
                    variables in php are denoted by the $ symbol. they may or may not include a var before them to handle scope. generally, you'd want to post the php file with your questions. It will make it easier on all of us to help you. If you can, post the php file and we can tell you how to set up your movie to get what it is that you want.
                    • 7. getting PHP to communicate with FLASH
                      em_shomer Level 1
                      <?php
                      $eName=$_POST['visitor_name'];
                      $eEmail=$_POST['visitor_email'];
                      $subject = 'A Message from a Bodyshop client';
                      $eComments=$_POST['visitor_comments'];

                      $toaddress="my@email.com";

                      if(mail($toaddress,$subject,$message,"From: ".$name." <".$email.">")){
                      $Name='';
                      $Email='';
                      $subject='';
                      $Comm ='';
                      $Phone =";
                      echo "&response=passed";
                      } else {
                      echo "&response=failed";
                      }
                      ?>
                      • 8. Re: getting PHP to communicate with FLASH
                        kglad Adobe Community Professional & MVP
                        there's no email_to. fix that in $toaddress.
                        • 9. Re: getting PHP to communicate with FLASH
                          em_shomer Level 1
                          i left my email out on purpose...

                          can you maybe or someone just explain how to set up the PHP form from my actionscript posted:

                          stop();

                          // -------------------<send form LoadVars>------------------- \\
                          var gatherForm:LoadVars = new LoadVars();

                          function sendForm() {
                          gatherForm.email_to = "eric.shomer@gmail.com";
                          gatherForm.visitor_comments = eComments.text;
                          gatherForm.visitor_name = eName.text;
                          gatherForm.visitor_email = eEmail.text;
                          gatherForm.visitor_phone = ePhone.text;

                          gatherForm.send("form.php", "POST");
                          }
                          // -------------------</send form LoadVars>------------------- \\

                          //--------------------<submit button AS>---------------------\\

                          // onRelease
                          submitBtn.onRelease = function() {
                          if (eEmail.text == "" || ePhone.text =="" || eName.text == "" || eComments.text == "") {
                          gotoAndStop("error");
                          } else {
                          sendForm();
                          gotoAndStop("correct");
                          }
                          }

                          //--------------------</submit button AS>---------------------\\
                          • 10. Re: getting PHP to communicate with FLASH
                            kglad Adobe Community Professional & MVP
                            there should be nothing to setup except to be sure you swf and your php script are in the same directory, your php is receiving all the variable/values it expects and your php script has permissions granted to be read and executed by everyone.
                            • 11. Re: getting PHP to communicate with FLASH
                              em_shomer Level 1
                              what im saying is: pretend I dont have a PHP script...by looking at actionscript posted above. How would you set up the PHP.
                              • 12. Re: getting PHP to communicate with FLASH
                                Level 7
                                em_shomer wrote:
                                > I dont have the book

                                You don't need the book. Download the sample chapter from the link on
                                that page. It's a free PDF file which gives step by step instructions
                                for what you're trying to do.

                                --
                                David Powers, Adobe Community Expert
                                Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
                                Author, "PHP Solutions" (friends of ED)
                                http://foundationphp.com/
                                • 13. getting PHP to communicate with FLASH
                                  SymTsb Level 2
                                  Ok. I've included your code with a few additions.

                                  First and foremost, whenever I'm sending data from a contact form, I always make sure to do something with the response so that I know first hand that the backend php communications are working. This is often times just a simple trace during testing to see what response was received by LoadVars.

                                  Examining your AS, I noticed a few things.

                                  First, you used mail.php as your file. If you are testing on the local system, this isn't going to work...not unless you have a PHP parser installed and running on your system when you are testing inside Flash. You need to rewrite the url and include the full URL to the file on the webserver i.e. www.mydomain.com/php/mail.php or whatever the url is for the mail.php file on your server.

                                  Second, you are sending the user off to "correct" before you even know for sure that there was a successful communication with the mail.php file at all. I added a second LoadVars to your AS as well as changed the line gatherForm.send(...) to gatherForm.sendAndLoad(....). This way, you know for certain that the file in question (mail.php) is both legit, ready and working and you'll also know that you have received the data back from that file.
                                  • 14. Re: getting PHP to communicate with FLASH
                                    em_shomer Level 1
                                    still not working...but thanks for the effort...i officially give up
                                    • 15. Re: getting PHP to communicate with FLASH
                                      SymTsb Level 2
                                      What did you do based on my last post? No offense, but it's not customary for us to write people step by step instructions for everything. We assume that people have a pretty basic understanding of the technology they wish to use. Getting aggravated because you don't know php or actionscript isn't going to solve the problem.

                                      And be specific.... What exactly is not working? Are you not getting the e-mail? Is it not going to the frame label you want? What are the instance names of each text field in the form? Do these match exactly to those in your sendForm function to be sent by LoadVars? Does your server support PHP and if so, does it allow mail()? This stuff all makes a huge difference. Have you tried to use the php file on it's own in an html form? If not, I'd try that first.

                                      Another idea, post the fla file and the php file via zip. kglad, myself and others will gladly download it and look at it to see what if anything we notice. There may be other conflicts inside your fla file that are botching up the LoadVars etc that you may not see. A fresh set of eyes never hurts. Giving us the code many times is not going to be enough to give the clearest picture of the problem. We'd rather you learn than get frustrated and give up.
                                      • 16. Re: getting PHP to communicate with FLASH
                                        em_shomer Level 1
                                        Please understand it is very hard to communicate effectivly in a message board when you are new to something I have a basic understanding of the material, but i dont know anything about PHP, hence the reason I am here. Anyway I would really like to get this fixed and see what my mistake is. If anybody is willing to take a look at it and help me out with it I would really appreciate it. Furthermore If you are able to get it working I will be happy to compensate for your troubles.
                                        I am attaching a link to a zip file of the contact form, PHP and swf files.

                                        link
                                        • 18. getting PHP to communicate with FLASH
                                          em_shomer Level 1
                                          Thanks for the help...I am still having a problem. I am able to advance to the correct frame label, but nothing is happening. I am not getting emails. Perhaps there is something either with my email or on the server. I appreciate your help
                                          • 19. Re: getting PHP to communicate with FLASH
                                            kglad Adobe Community Professional & MVP
                                            is your email address correct in the php file? do you receive an email when you test contactForm.html on the above site?
                                            • 20. Re: getting PHP to communicate with FLASH
                                              em_shomer Level 1
                                              Well email is correct in PHP file as well as Flash File. I would have liked to try it out on your site, but unfortunatly link is broken
                                              • 21. Re: getting PHP to communicate with FLASH
                                                SymTsb Level 2
                                                There were some issues in the original PHP file. I'm not sure if you ever corrected those but they existed in the mail() line which meant that the e-mail would never send. Below is the correct php file. Just copy and paste and then insert your e-mail in the correct line. Try it again, and get back to me.
                                                • 22. Re: getting PHP to communicate with FLASH
                                                  kglad Adobe Community Professional & MVP
                                                  i corrected the php file and the swf.

                                                  the test link was missing a w so you can retest yourself with the obvious addition of the third w.

                                                  i also sent a test email using the contact form which you should receive sometime after 8:40am pst.
                                                  • 23. Re: getting PHP to communicate with FLASH
                                                    em_shomer Level 1
                                                    Still no email. I am using the original PHP and Swf sent in the zip file from last evening. I can still get to the frame label that says the message was sent, but there is no email.

                                                    <?php
                                                    $to = "eric.shomer@gmail.com";
                                                    $name = $_POST['visitor_name'];
                                                    $email = $_POST['visitor_email'];
                                                    $message = $_POST['visitor_comments'];
                                                    $phone = $_POST['visitor_phone'];
                                                    $subject = 'A Message from a Bodyshop client';


                                                    $headers = 'MIME-Version: 1.0' . "\r\n";
                                                    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                                                    $headers .= 'From:'. $name .' <' . $email . '>' . "\r\n";

                                                    $ok = mail($to, $subject, $message, $phone, $headers);
                                                    if($ok) {
                                                    echo "&response=passed&";
                                                    } else {
                                                    echo "&response=failed&";
                                                    }

                                                    ?>


                                                    SWF******
                                                    this.stop();
                                                    // -------------------<send form LoadVars>------------------- \\
                                                    var gatherForm:LoadVars = new LoadVars();
                                                    var receiveForm:LoadVars = new LoadVars();
                                                    receiveForm.onLoad = function() {
                                                    if (this.response == "passed") {
                                                    name_txt.text = "";
                                                    email_txt.text = "";
                                                    phone_txt.text = "";
                                                    msg_txt.text = "";
                                                    trace("email sent");
                                                    gotoAndStop("correct");
                                                    }
                                                    };
                                                    function sendForm() {
                                                    gatherForm.email_to = "eric.shomer@gmail.com";
                                                    gatherForm.visitor_comments = msg_txt.text;
                                                    gatherForm.visitor_name = name_txt.text;
                                                    gatherForm.visitor_email = email_txt.text;
                                                    gatherForm.visitor_phone = phone_txt.text;
                                                    // You may want to try the absolute http to this file i.e. http://www.mydomain.com/form.php
                                                    // If you are testing on the local system and it doesn't know how to parse php,
                                                    // you'll never get a response back from the file.
                                                    gatherForm.sendAndLoad(" http://www.bodyshopfitnesscenter.com/sources/Flash/form.php", receiveForm, "POST");
                                                    }
                                                    // -------------------</send form LoadVars>------------------- \\
                                                    //--------------------<submit button AS>---------------------\\
                                                    // onRelease
                                                    submitBtn.onRelease = function() {
                                                    if (email_txt.text == "" || phone_txt.text == "" || name_txt.text == "" || msg_txt.text == "") {
                                                    gotoAndStop("error");
                                                    } else {
                                                    sendForm();
                                                    }
                                                    };
                                                    //--------------------</submit button AS>---------------------\\

                                                    • 24. Re: getting PHP to communicate with FLASH
                                                      kglad Adobe Community Professional & MVP
                                                      if you're not getting the email from my test link it's because the email address is incorrect (which i know you've checked) OR my server has restrictions on using their server sending emails to non-authorized recipients (which is highly likely).

                                                      but if you're having trouble using your server check your servers email policies. that email address may not be an authorized recipient of emails sent from your server.
                                                      • 25. getting PHP to communicate with FLASH
                                                        em_shomer Level 1
                                                        correction it will go to the frame label now that I have the PHP in the same location as the SWF. but still no email I will check with the server to make sure that email will work
                                                        • 26. Re: getting PHP to communicate with FLASH
                                                          kglad Adobe Community Professional & MVP
                                                          unzip the files i sent. upload the html file and php file using ascii protocol. upload to the same directory the swf file using binary protocol. retest.
                                                          • 27. Re: getting PHP to communicate with FLASH
                                                            depakchopra Level 1
                                                            Thats a very insightful and appreciated chapter you have online. Thanks for mentioning it as I am trying to learn the same thing.
                                                            • 28. Re: getting PHP to communicate with FLASH
                                                              em_shomer Level 1
                                                              Ok last question, and then I will shut up because I am sure everybody is annoyed with this thread. I just dont understand why it can work one place and not the other. I changed the email address, thinking maybe that had something to do with it. Im not sure if my hosting company supports sending email to an external address, so I invented a new email that has the same domain name and updated that in both my PHP and swf files, and still nothing, but I can tell it is communicating because there is a small delay when i hit the send button which is why I think it is receiving the data in the PHP file but it is not sending. If you could check the PHP file one more time and see if you can pick out anything that looks odd, I would appreciate it.
                                                              • 29. Re: getting PHP to communicate with FLASH
                                                                SymTsb Level 2
                                                                I see one thing that stands out. It's the $phone variable.

                                                                Here is the syntax (from php.net) for the mail function

                                                                bool mail ( string $to, string $subject, string $message [, string $additional_headers [, string $additional_parameters]] )

                                                                According to your php file, the following information is being sent.....

                                                                $to is right
                                                                $subject is right
                                                                $message is right
                                                                $phone is wrong (this should be sent inside the body of your message if you want their phone number)... according to the mail functions parameters, this would be header information and since this is going to be ###-###-#### and not of the form MIME blah blah blah, the server receiving the e-mail is going to reject it. change your mail line to this....

                                                                mail($to, $subject, $message, $headers)

                                                                also change the variable call to message to this....

                                                                $message = $_POST['visitor_comments']." ".$_POST['visitor_phone'];

                                                                and get rid of the $phone = $_POST['visitor_phone']; line as it won't be necessary.