7 Replies Latest reply on Nov 27, 2010 3:37 PM by kglad

    AS1 and 2 reading from PHP

    ssamuels222

      Hello.

       

      I have a php file which ends with:

       

       

      if (mail($mailto,$subject,$message, $headers)) {
      $message_back = "Success";
      echo "Success";

      } else {
      $message_back = "Your email could not be processed";
      echo "No Success";
      }

      I can loadVars into it just fine and it sends the email as well.

      My question is: How do I read back into AS1 the variable message_back.

      or is echo also read into as1.

       

      I am new to this subject and still trying to understand the communication aspect of it.

       

      Thanks for any insight on this. Samantha

        • 1. Re: AS1 and 2 reading from PHP
          kglad Adobe Community Professional & MVP

          with as1, you have to use loadVariables and start a loop that awaits the php return.

          1 person found this helpful
          • 2. Re: AS1 and 2 reading from PHP
            ssamuels222 Level 1

            Hi kglad

             

            I think, I do have a loop in as1 and it uses loadVariables but my question is how do I read into as1 the php variable $message_back. or the echo?

             

            Do I assign it to a varialble?

            Does as1 just knows that message_back exists.

            Do I have to have message_back in as1 empty until I get the message back and then assign it to it.

             

            This is my script on my submit button. The function below (what I think is my loop) checks for the output to be sent. But I don't know if 'sent' is an actual variable that Flash just understands to check for success:

             

            on (release) {
                  if (conditions for success-sorry I took these out because it was too long and it didn't keep the format)
                   {
                         sender_name = _root.pag.pages.page7.tf_1;
                         sender_email = _root.pag.pages.page7.tf_3;
                         sender_message = _root.pag.pages.page7.tf_4;
                         message_back = _root.pag.pages.page7.cfMessage;
                         loadVariables("process.php",this, "POST");
                         _root.pag.pages.page7.cfMessage = "Processing...";
                         _root.pag.pages.page7.tf_1 = "";
                         _root.pag.pages.page7.tf_3 = "";
                         _root.pag.pages.page7.tf_4 = "";
                         this.onData = function()    {     
                               if(this.output ne 'sent')  {// in case of error   
                                    _root.pag.pages.page7.cfMessage = "Your message was not sent by the server. Please check your email.";
                                     Selection.setFocus("_root.pag.pages.page7.tf_3");
                                     _root.pag.pages.page7.b = 1;
                                     _root.pag.pages.page7.tf_1 = sender_name;
                                     _root.pag.pages.page7.tf_3 = sender_email;
                                     _root.pag.pages.page7.tf_4 = sender_message;
                               } else { //   Success!"; 
                                     _root.pag.pages.page7.cfMessage = "Thanks for your message. Someone will get back to you shortly";
                                     Selection.setFocus("_root.pag.pages.page7.tf_1");
                                     _root.pag.pages.page7.b = 0;
                
                          }
                _root.pag.pages.page7.bSubmit.enabled = false;
               }
              
            }
              
            else {
                   if (_root.pag.pages.page7.tf_1 eq "") {
                         _root.pag.pages.page7.cfMessage = "Please enter a name";  
                             Selection.setFocus("_root.pag.pages.page7.tf_1");}
                   else if (_root.pag.pages.page7.tf_3 eq "") {
                         _root.pag.pages.page7.cfMessage = "Please Enter a valid email"; 
                         Selection.setFocus("_root.pag.pages.page7.tf_3");}
                   else if (EMAIL CONDITIONS-too long to fit properly ) {
                         _root.pag.pages.page7.cfMessage = "Please Enter a valid email"; 
                         Selection.setFocus("_root.pag.pages.page7.tf_3");}
                  else if (_root.pag.pages.page7.tf_4 eq ""){
                          _root.pag.pages.page7.cfMessage = "Please write your message"; 
                          Selection.setFocus("_root.pag.pages.page7.tf_4");}
            }
               
            }

             

            Thanks, Samantha

            • 3. Re: AS1 and 2 reading from PHP
              kglad Adobe Community Professional & MVP

              use:

               


               

               

              if (mail($mailto,$subject,$message, $headers)) {
              echo $message_back = "Success";

              } else {
              echo $message_back = "Your email could not be processed";
              }


              and look for message_back to be defined to terminate your loop and respond to the value.
              • 4. Re: AS1 and 2 reading from PHP
                ssamuels222 Level 1

                Hi Kglad,

                 

                I followed your lead and used:

                ----------------------------------------

                if (mail($mailto,$subject,$message, $headers)) {
                echo $message_back = "Success";

                 

                } else {
                echo $message_back = "Your email could not be processed";
                }

                ----------------------------------------------------------------------
                I then waited for message_back but Flash never saw it.

                -------------------------------------------------------------------------------

                I now changed it to:

                ------------------------------------------------------------------------------

                     if (mail($mailto,$subject,$message, $headers)) {
                          echo "$response= Success";

                     } else {
                          echo "$response= Server Error";
                     }

                ------------------------------------------------------------------------------------------ --------------------------------------------------------------

                Also I decided to make it a bit more formal in Flash and did this for my function to receive the variables:

                ------------------------------------------------------------------------------------------ --------------------------------------------------------------

                on (release) { //within my submit button
                //I created 2 LoadVars objects to send data and receive it back from PHP
                      dataSender = new LoadVars();
                      dataReceiver = new LoadVars();

                //Then I proceeded to check my conditions for the input fields

                            if ( everything is ok anf filled)
                                 { // I then assigned the Loadvars objects my input fields            

                                  dataSender.sender_name = _root.pag.pages.page7.tf_1;
                                  dataSender.sender_email = _root.pag.pages.page7.tf_3;
                                  dataSender.sender_message = _root.pag.pages.page7.tf_4;
                                  dataSender.message_back = _root.pag.pages.page7.cfMessage;

                               // I now tell the user that the information is been processed
                                  _root.pag.pages.page7.cfMessage = "Processing...";
                                  _root.pag.pages.page7.tf_1 = "";
                                  _root.pag.pages.page7.tf_3 = "";
                                  _root.pag.pages.page7.tf_4 = "";
                               //I now use the onload attribute to receive feedback from PHP

                               dataReceiver.onLoad = function() {
                                  _root.pag.pages.page7.cfMessage = "After Function";
                                   if (this.response eq "Success") {
                                         _root.pag.pages.page7.cfMessage = "Success"; //This is to test if it is going through this I want to use the dataReceiver.response below
                                         _root.pag.pages.page7.cfMessage = dataReceiver.response;
                                         _root.pag.pages.page7.cfMessage = "Thank you for your message. Someone will get back to you shortly.";
                                   }
                                   else if (this.response eq "error") {
                                         _root.pag.pages.page7.cfMessage = "Error"; //This is to test if it is going through this
                                         _root.pag.pages.page7.cfMessage = dataReceiver.response;
                                         _root.pag.pages.page7.cfMessage = "Please check email address - does not appear valid."
                                   }
                                   else if (this.response eq "Server Error") {
                                   _root.pag.pages.page7.cfMessage = "server error";
                                   _root.pag.pages.page7.cfMessage = "Your message was not sent. There seems to be a server error";
                                   _root.pag.pages.page7.cfMessage = dataReceiver.response;
                                  }
                        }

                             dataSender.sendAndLoad("process.php", dataReceiver, "POST");
                  
                             _root.pag.pages.page7.bSubmit.enabled = false;
                             _root.pag.pages.page7.cfMessage = "after enabled";
                  }
                  
                else {
                            if (if the fields are blank or have the wrong information) {
                                  _root.pag.pages.page7.cfMessage = "Please enter correct and valid info";  
                }

                 

                ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------

                Flash still does not see it. I do get the emails so the form is been processes correctly

                I also used an html form to check PHP and PHP echoes back response=Success

                So I know PHP is executing but Flash AS1 does not see "response"

                 

                Can you see anything I am doing wrong? I would really appreciate it. Sorry for the long coding. I tried to shorten it as much as I thought was logical.

                 

                Thanks S.

                • 5. Re: AS1 and 2 reading from PHP
                  kglad Adobe Community Professional & MVP

                  are you publishing for fp 6 or better?

                  • 6. Re: AS1 and 2 reading from PHP
                    ssamuels222 Level 1

                    Hi Kglad,

                     

                    I am publishing for Flash 6 AS1.

                    I discovered that I could not pass the "if" conditions because flash is reading a lot of url encoding symbols like %20 etc.

                     

                    I thus change my AS1 in Flash to the following and now it reads the php which I also changed (see below).

                    But I still have 2 problems. First: The condition is always testing "true" even when the email is not sent. Second: The variables read have all these characters embedded when Flash reads them (%20 etc). I placed comments within the code to tell you what "I think" is happening.

                     

                    This is the AS1 on my submit button:

                    ---------------------------------------------------------------

                    on (release) {
                    //create the LoadVars objects which will be used to send data...
                    var dataSender = new LoadVars();
                    //and one to catch what comes back
                    var dataReceiver = new LoadVars();
                    /*dataReceiver.onLoad = getResponse;*/

                      if ( all conditions for input field are met )
                           {
                            dataSender.sender_name = _root.pag.pages.page7.tf_1;
                            dataSender.sender_email = _root.pag.pages.page7.tf_3;
                            dataSender.sender_message = _root.pag.pages.page7.tf_4;
                            dataSender.message_back = _root.pag.pages.page7.cfMessage;
                            _root.pag.pages.page7.cfMessage = "Processing...";
                            _root.pag.pages.page7.tf_1 = "";
                            _root.pag.pages.page7.tf_3 = "";
                            _root.pag.pages.page7.tf_4 = "";
                            dataReceiver.onLoad = function(phpresult) {
                             if (phpresult eq true) {
                               _root.pag.pages.page7.cfMessage = dataReceiver;
                              /*_root.pag.pages.page7.cfMessage = "Thank you for your message. Someone will get back to you shortly."*/
                              /*_since I only have a message coming back. I don't have to use a for loop to read an array*/
                        }
                        else if (phpresult eq "one") {
                              /*For "one" I just send "one" in php so I have to write the answer here.*/
                              _root.pag.pages.page7.cfMessage = "Please check email address - does not appear valid."
                           }
                        else if (phpresult eq false) {/dataReceiver contain an error at server
                         _root.pag.pages.page7.cfMessage = dataReceiver
                           }
                       }
                       _root.pag.pages.page7.bSubmit.enabled = false;
                       dataSender.sendAndLoad("process.php", dataReceiver, "POST");
                      }
                      
                    else { // if blank or email has no @ or "." or is blank between @ and ".". Ask user to fix.
                      if (if user needs to fix his input it goes here){
                    }
                       
                    }

                     

                     

                    --------------------------

                    This is the php loop

                    ------------------------

                    if (mail($mailto,$subject,$message, $headers)) {
                    $message_backorig="Success";
                    $message_back=rawurlencode ($message_backorig);
                    echo "&$message_back";
                    $dataReceiver .='&';
                    echo "&$dataReceiver";

                    //echo sends back a true or false response to flash.
                    //If I don't put the "&" percent is just does not read anything in flash
                    //But this loop is always true based on flash and it never waits for it to be false. Also the

                    // &$dataReceiver is read with the %20 characters like so  -- Success=&%0D%0A%0D%0A=&onLoad=%5Btype%20Function%5D

                    //So it gives me the "Success" from been true but it adds all this other stuff" With an html form I test the same php and it returns just &Success&&

                    } else

                    {
                    $message_back="Server Error. Please check your email";
                    echo "&$message_back";
                    $dataReceiver .='&';
                    echo "&$dataReceiver";
                    }

                     

                    Thanks Kglad. Agian the answer to your question is Flash 6 As1

                    • 7. Re: AS1 and 2 reading from PHP
                      kglad Adobe Community Professional & MVP

                      i can't read that actionscript it's formatted so badly.  fix that so it's readable.