3 Replies Latest reply on Jan 28, 2009 10:18 AM by Newsgroup_User

    Post without Submit

    dbranch
      I am trying to post a some form variables to another site (Google Checkout). They have a HTML API for handling this and when I a user on my site clicks the submit button the action calls a Google URL and I pass them some form variables and all works well. However I want to do i some server side processing before I send the form request to Google for payment processing (i.e set up user in my database) and then send them to google. The problem is that I need to perform a form submit and am not sure how to do this from the server. I believe cfhttp can handle this but I don't want to capture the response; I just want to pass them to Google as a normal form submit would do so they can continue with the checkout process. Any suggestions?

      Thanks
        • 1. Re: Post without Submit
          Level 7
          dbranch wrote:
          > Any suggestions?
          >
          > Thanks
          >

          What you are looking for here is for a bit of a split personality from
          the client. I.E. "Please Mr. Browser submit this data to both My server
          and Google's server at the same time...".

          That is not how the normal http request/response cycle works so you are
          going to have to get creative.

          My first thought is to go ahead and use the <cfhttp...> functionality.
          It is what it is designed for. Then just capture the content and return
          it to the client. I.E. <cfoutput>#cfhttp.fileconent#</cfoutput>. I
          think that is the easiest and should work fine.

          If you truly want the client to submit to both servers, I can only
          imagine doing this with some JavaScript. I'm guessing that you could
          intercept the form submit event, and then use some JavaScript to make an
          AJAX asynchronous submit to one of the servers, before doing a normal
          post submit to the other. But that sounds much more convoluted to me.
          • 2. Re: Post without Submit
            coffeedrinker56
            (1) Change the form action to point to a JavaScript function:
            <form name="abc" method="post" action="javascript:readData();" >
            ...
            (2) Strip the information you want from the form and send the stripped data synchronously (via Ajax) to your receiving CF script;
            ...
            (3) Create another function to receive "good" or "bad" responses from the server;
            ...
            (4) set the last 2 lines in the 2nd javascript function to ...
            document.getElementsByTagName("form")[0].setAttribute("action", original_google_action);
            document.getElementsByTagName("form")[0].submit();

            Note that you want to send the data synchronously in case your CF script fails. Otherwise you've lost any chance of collecting the data.
            • 3. Re: Post without Submit
              Level 7
              P.S.

              Forgot a third option.

              You could have the form submit the data to your server. Do what
              processing you desire. Then build a new form with all the data in hidden
              fields with the action set to the Google server. Return this form to
              the client with javacript that fires in the onload event that
              automatically submits the form.

              But I'm not sure this would work anymore. Browsers intercept these
              types of automatic javascript user actions these days to prevent their
              abuse by spammers and hackers.