Link to home
Start Free TrialLog in
Avatar of MMsabry
MMsabry

asked on

cfhttp

Can someone give me an example on how to use cfhttp

I'm trying to post some information from my site (hidden form fields) to an online processor,
so i have a page where the hidden form fields are populated with data, then the form submits to a page which contains only a cfhttp tage, but nothing happens.
here is the cfhttp tage that i wrote

<cfhttp  redirect="yes"  url="https://www....." method="post" resolveurl="yes" >
                                          
                                          <cfhttpparam name="sid" type="formfield" value="#form.sid#">
                                          <cfhttpparam name="total" type="formfield" value="#form.Total1#">
                                          <cfhttpparam name="cart_order_id" type="formfield" value="#form.cart_order_id# ">
                                          <cfhttpparam name="demo" type="formfield" value="#form.demo#">
                                    </cfhttp>  
                                    </cfif>
thanks
Avatar of pinaldave
pinaldave
Flag of India image

value="#form.cart_order_id# "
there is a space at the end of this variable before " does that matter...
Avatar of MMsabry
MMsabry

ASKER

thanks, but nop nothing happens, no redirection!
have you tried creating a normal form and post to this page?
example
<form method="post" action="http://..">
<input ype="text" name="sid" value="test">
etc.....
</form>
SOLUTION
Avatar of jyokum
jyokum
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you want to see what was returned from the cfhttp call, put this after it.

<cfdump var="#cfhttp#">

After you make a cfhttp call, you will get back a structure called "cfhttp" that contains all the return information
Avatar of MMsabry

ASKER

Jyokum,
what is the use of the "redirect" attribute of the cfhttp tag then?

Tacobell777'
i have tried that, but nop it does not work.

you see the page i'm posting the info to is the first page of an online processor, and they need the info to be appended to the url, which is easy, my only problem with this, is that the user can see and edit the info on the url and the processor will make him pay the edited amount, which is something i do not want to happen. they indicated to me that their security against that is to send back a hashed key with some information that would allow me to verify that the user has payed the correct amount. but i want to try to avoid this from the start, since if this happens (user editing the total amount) and pays, it will be up to me to chase him to get the correct amount from the start.

now i have once managed to get the cfhttp tag to work (which i do not remember how) and passed all the information correctly without the  rest of the url showing the info. as url param. but at that one time, only the first page on the processor got the information (this page asks the user how does he want to pag) then it moves to the second page where the payment itself occurs. this second page did not get the information and thus displayed a total of "0".

so one thing i was trying to do, is to pass the information using the cfhttp tag, and append the variables to it as hidden form fields. this is where i'm stuck at the moment.

any solutions or work arounds??
thanks
sabry
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MMsabry

ASKER

the payment service is 2checkout.com
I have got the the payment processor to work, but only if the user presses a submit button (hidden form fields are submitted then), i would still like to get it to just redirect. so the user does not have to press submit three times through the process
first submit, then verify and submit then pay. I would like to take that last step out, and just diplay a page for about 10s. then it goes to the processor.

I would like also to know how to use the cfhttp tag, and why it is not redirecting in my case!
thanks
You mention that the service you are submitting to requires the information appended to the URL.  The way you are executing your cfhttp it is submitting form POST data.  What you want to do is submit form GET data.  Adjusting your code it would look like the following:

<cfhttp  url="https://www....." method="get" resolveurl="yes">
     <cfhttpparam name="sid" type="URL" value="#form.sid#">
     <cfhttpparam name="total" type="URL" value="#form.Total1#">
     <cfhttpparam name="cart_order_id" type="URL" value="#form.cart_order_id# ">
     <cfhttpparam name="demo" type="URL" value="#form.demo#">
</cfhttp>

You will receive the http response back from the server in the #cfhttp.FileContent# variable.  After your cfhttp block you will need to parse this variable to get your payment status code.

The redirect parameter in cfhttp is defaulted to YES.  This parameter allows the cfhttp request to accept and execute redirects from the url requested up to 4 times.  It DOES NOT perform any kind of redirection for the page user.

After you parse your status code then you will want to do one of two things:
Execute a <cflocation url="statuspageX.cfm"> tag that redirects the user to a special status explanation page -or-
if you want to show them their status and redirect them after 10 seconds or so then you will have to use a javascript timer.