15 Replies Latest reply on Nov 16, 2007 2:01 PM by Greg Dove

    .send v .sendAndLoad

    Nick Barling Level 1
      Hi all,

      I have a simple sendForm(); function that compiles vars, builds a form in AS2 and sends the form to a CGI script on the host ISP for email delivery. I use the LoadVars object to collect and send the vars to the CGI script. The final part of the function sends the data to a URL and targets a blank window for a return message and uses the POST method. All works fine when the form is submitted using a simple button and the .send method of the LoadVars class.

      However, I want to prevent the default CGI script return page from appearing by preventing the browser opening a new window (or replacing the swf using _self), so I used the .sendAndLoad method and replaced the 'window' target with a gotoAndStop frame, which carries a successful deliver message.

      The problem is that the form date is not posted to the URL, but the swf does advance to the gotoAndStop frame, which shows the successful delivery message. Can anyone tell me why the date is not being sent to the URL with the .sendAndLoad method?


      var feedbackForm:LoadVars = new LoadVars();

      function sendForm() {
      feedbackForm.recipient = "info@somedomain.com";
      other form constructs here
      feedbackForm.sendAndLoad(" http://formmail.dreamhost.com/cgi-bin/formmail.cgi", gotoAndStop("correct"), "POST");

      this.contactForm.submitBtn.onRelease = function() {
      if ( form validation here) {
      } else {

      This problem is vexing to say the least and it is not the first time that I have had .sendAndLoad issues. Any help is very much appreciated.
        • 1. .send v .sendAndLoad
          Greg Dove Level 4
          The second argument for the sendAndLoad method is an Object. I've never seen it used other than with another LoadVars (or sometimes the same LoadVars) instance or an XML instance.

          I would code a receiving LoadVars for your sendAndLoad and wait for its onLoad handler to fire then advance to your 'correct' frame. Or just sendAndLoad, advance to a 'correct, please wait' frame and then confirm when the onLoad handler fires.
          • 2. Re: .send v .sendAndLoad
            Nick Barling Level 1
            Excellent answer, thanks.
            • 3. Re: .send v .sendAndLoad
              Greg Dove Level 4
              No problem - I adjusted your code with an example that (hopefully) will help.
              • 4. Re: .send v .sendAndLoad
                Greg Dove Level 4
                Actually I just saw its dreamhost, probably you have to live with whatever it returns?

                If so, just use the onData handler instead of onLoad. The argument is the raw text that the script sends in response. I guess its might be a web page. You could ignore it then and move on.
                • 5. Re: .send v .sendAndLoad
                  Nick Barling Level 1
                  Yes, its a default html web 'thank you' type page that they return.

                  Do I drop the URL encoded value from the if statement and just look for a return of data?
                  • 6. .send v .sendAndLoad
                    Greg Dove Level 4
                    Instead of using onLoad, use onData like this:

                    • 7. Re: .send v .sendAndLoad
                      Greg Dove Level 4
                      A quick question: can you access that script? You will need crossdomain permission if you're not on that domain. It seems that therealsuperhero has access.


                      • 8. Re: .send v .sendAndLoad
                        Nick Barling Level 1
                        I am on the domain but I do need out of domain access, which I have achieved by forwarding the email from within Dreamhost's web panel (pain in the neck), especially as Comcast has refused to accept redirects/forwards. Sigh.

                        The code looks good but I am getting a syntax error? Can't see it, but FL suggests the: submitFeedbackResponse.onData(src) { line?

                        var feedbackForm:LoadVars = new LoadVars();
                        var submitFeedbackResponse:LoadVars = new LoadVars();

                        function sendForm() {
                        feedbackForm.recipient = "info@ssmiles.com";
                        feedbackForm.realname = contactForm.userName.text;
                        feedbackForm.email = contactForm.userEmail.text;
                        feedbackForm.feedback = contactForm.userComments.text;

                        feedbackForm.sendAndLoad(" http://formmail.dreamhost.com/cgi-bin/formmail.cgi", submitFeedbackResponse, "POST");

                        submitFeedbackResponse.onData(src) {
                        if (src !=undefined) {
                        } else {
                        • 9. Re: .send v .sendAndLoad
                          Greg Dove Level 4
                          sorry, I had a typo originally which I corrected.
                          submitFeedbackResponse.onData=function(src) {
                          • 10. Re: .send v .sendAndLoad
                            Nick Barling Level 1
                            OK, got that, thanks.

                            \On testing the script, from the live server, I am getting the 'error' frame and the data is not being sent.

                            Is this because the submitFeedbackResponse.onData(src) function is firing before the sendForm() function, and causing the src to be undefined as the script has not returned anything?
                            • 11. .send v .sendAndLoad
                              Greg Dove Level 4
                              submitFeedbackResponse.onData only fires and sends it to the 'error' frame if there's an error with the data exchange. I believe its a crossdomain issue and that unless your swf is hosted at formmail.dreamhost.com or unless you're somehow proxying that request via a script on the server at your own domain that it won't work.

                              Are you using windows? If so I would check what's happening with Fiddler2 (HTTP debugger) . This will let you see if its trying to load a policy file first and failing, or if there's some problem with the LoadVars exchange after that.
                              • 12. Re: .send v .sendAndLoad
                                Nick Barling Level 1
                                Good points.

                                The swf is hosted at dreamhost but obviously not in their email web server, but nevertheless it is in their server system. The form was processed correctly through the .send method so I can't see a cross-domain issue affecting the .sendAndLoad method usage and not the .send method.

                                I'll check the handling with Fiddler2 and see what that throws up.

                                Thanks for some really great help!
                                • 13. Re: .send v .sendAndLoad
                                  Greg Dove Level 4
                                  Good luck with it. I think there's a difference for permissions where data loading is concerned.
                                  The send method is just like the browser sending and loading. Flash doesn't get access to the response.

                                  For load and sendAndLoad it requires permission. At least that's the way I read the docs. I might be wrong.

                                  • 14. Re: .send v .sendAndLoad
                                    Nick Barling Level 1
                                    On checking the docs you could be right about data handling; it seems that pre Flash v7 you could handle/pass data between/within a superdomain but post v7 players cannot handle data outside the exact same domain. If that is true then I cannot handle data through the sendAndLoad method (I am using Player 8+).

                                    So, with that in mind I went back to the onLoad method but I am still getting a post failure, that is, the data is not being sent to the URL.

                                    I'll post the answer here when I get one. I can't believe that you cannot use the sendAndLoad method to handle/post form data and email with the express aim of preventing the CGI script returning an unwanted web page or other data. Especially as the Flash documentation tells you to use .sendAndLoad in preference to .send to prevent the returning html opening in a new window.

                                    Oh well, I guess this is an example of why we don't actually sleep anymore!
                                    • 15. .send v .sendAndLoad
                                      Greg Dove Level 4

                                      I can't believe that you cannot use the sendAndLoad method to handle/post form data and email with the express aim of preventing the CGI script returning an unwanted web page or other data

                                      -The assumption is that (in alignment with the secuirty measures) you have control over the server scripting and get them to return what you want... or that if someone else exposes their functionality to flash via crossdomain permissions, then its intended to return something that flash can use.

                                      The other option here would be to ask Dreamhost to grant permission for its other subdomains in their (existing) crossdomain.xml file there. Doesn't seem unreasonable...

                                      You might be able to get it to work as is if you publish your swf for player 6 version and you're on the dreamhost.com domain somewhere. I think most of the security changes were designed not to break older flash content....