2
votes

I'm working on a Coldfusion page that takes information from a form and posts back to the same page. However, I have a CFHTTP URL string that I want to POST to a PHP page and I want to open in a separate page as well (still leaving the original POST page open. I thought CFHTTP would accept a "target - blank" value but it doesn't. Here's my code:

<cfhttp method="Post" url="https://www.foo.com/foocorp/restrict/fpdf/letter.php" result="adverseResponse">
            <cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0"> 
            <cfhttpparam type="Header" name="TE" value="deflate;q=0">
                <cfoutput>

                <cfif isdefined( "b_firstname" )><cfhttpparam name="B_FIRSTNAME" type="formField" value="#B_FIRSTNAME#"></cfif>
                <cfif isdefined( "b_lastname" )><cfhttpparam name="B_LASTNAME" type="formField" value="#B_LASTNAME#"></cfif>
                <cfif isdefined( "prop_address" )><cfhttpparam name="PROP_ADDRESS" type="formField" value="#PROP_ADDRESS#"></cfif>
                <cfif isdefined( "prop_city" )><cfhttpparam name="PROP_CITY" type="formField" value="#PROP_CITY#"></cfif>
                <cfif isdefined( "prop_state" )><cfhttpparam name="PROP_STATE" type="formField" value="#PROP_STATE#"></cfif>
                <cfif isdefined( "prop_zip" )><cfhttpparam name="PROP_ZIP" type="formField" value="#PROP_ZIP#"></cfif>

                </cfoutput>
        </cfhttp>

Is there another CF element I should be using instead of CFHTTP?

1

1 Answers

7
votes

There's a few misconceptions here. CFHTTP does server to server communication. Whatever happens in CF stays in CF (to coin a slogan). What you are referring to with target="_blank" is something that is happening on the client - where a separate "page" is opened in a "browser". CFHTTP doesn't use a browser. It doesn't render content. It just issues HTTP requests with various headers and params and gives you the response back - all on the server within your cf code. You have to "do" something with the content to send it back to the browser.

So what you need to do is either:

  • Take the response from CF (adverseResponse.filecontent) and place it in your separate page using a popup or whatever. In this way you are acting as a "proxy" for the browser.
  • Abandon the CFHTTP route and user jquery or Javascript or whatever to impliment the behavior that posts to the PHP directly in the browser.

Hope this helps.