Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / July 2006



Tip: Looking for answers? Try searching our database.

Emulating Form Post

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dremmeister - 26 Jul 2006 23:37 GMT
This code works fine and is an abbreviated version of the real thing:

<form class="unpadded" action="http://countycat.mcfls.org/search/a?a"
method="post">
<input type="hidden" name="searchtype" value="Y">
<input maxlength="75" name="searcharg" size="25">
<input type="hidden" name="searchscope" value="1">
<input type="hidden" name="SORT" value="D">
<input type="submit" value="Submit">    
</form>

This code returns nothing, any idea why?

<cfhttp method="post" url="http://countycat.mcfls.org/search/a?a">
<cfhttpparam type="Formfield" value="Y" name="searchtype">
<cfhttpparam type="Formfield" value="golf" name="searcharg">
<cfhttpparam type="Formfield" value="1" name="searchscope">
<cfhttpparam type="Formfield" value="D" name="SORT">
</cfhttp>

Any other options?  I am trying to do a single form that will search multiple
sites using a "POST".

Please help me out.:confused;
Ian Skinner - 26 Jul 2006 23:54 GMT
What do you mean by "This code returns nothing?"

I ask because you don't show anywhere where you are using the results
from the cfhttp call.  These results are not automatically dumped to the
output stream, rather they are stored in a variable named "cfhttp", or
any other variable you define with the "result" property of the
<cfhttp...> tag post MX7.

To use these results you would have to do something with
#cfhttp.fileContent# or #foobar.fileContent# if you had result="foobar"
in the <cfhttp...> tag.

> This code works fine and is an abbreviated version of the real thing:
>
[quoted text clipped - 20 lines]
>
>  Please help me out.:confused;
dremmeister - 31 Jul 2006 16:31 GMT
I understand your point.  The result I am looking for would be to EMULATE what
would happen in example 1 (as if the user pressed submit on the form and got
the results in their browser).

I don't know that the variable content would do that, would it?

Perhaps I am using the wrong command.  My understanding is that I could
emulate a form POST using JavaScript.

The objective is to get the exact same result in example 1.
Ian Skinner - 31 Jul 2006 17:40 GMT
You could probably also do this with JavaScript.  But to do it with your
ColdFusion example, you just need to process the results.

Assuming the code you provide is correct and returns the desire result.

 <cfhttp method="post" url="http://countycat.mcfls.org/search/a?a">
 <cfhttpparam type="Formfield" value="Y" name="searchtype">
 <cfhttpparam type="Formfield" value="golf" name="searcharg">
 <cfhttpparam type="Formfield" value="1" name="searchscope">
 <cfhttpparam type="Formfield" value="D" name="SORT">
 </cfhttp>

Just add this.

<cfoutput>#cfhttp.FileContent#</cfoutput>
<cfdump var="#cfhttp#">

If you add a result="foobar" to the cfhttp tag, you can do this.

<cfoutput>#foobar.FileContent#</cfoutput>
<cfdump var="#foobar#">

This is how cfhttp works.  It does not return the results to the output
stream, it returns the results to a variable that you then need to
process to do what you wish with it.  Lots of people don't want all the
results sent to the output stream.  They will further process them to
get just some desired pieces.

> I understand your point.  The result I am looking for would be to EMULATE what
> would happen in example 1 (as if the user pressed submit on the form and got
[quoted text clipped - 6 lines]
>
>  The objective is to get the exact same result in example 1.
dremmeister - 31 Jul 2006 19:38 GMT
Thanks very much Ian.

I added resolveurl=yes to pickup images, etc. and it worked like a charm.

The only (minor) issue I have left is the shopping cart links don't get
resolved correctly.  I think this is because the source code on THEIR website
uses JavaScript (onclick).  Any way around that one?

Here is the "new" code...

<cfhttp url="http://countycat.mcfls.org/search/a?a" columns="a" method="post"
resolveurl="yes" >
<cfhttpparam type="url" value="http://countycat.mcfls.org/search/a?a"
name="search">
<cfhttpparam type="Formfield" value="Y" name="searchtype">
<cfhttpparam type="Formfield" value="golf" name="searcharg">
<cfhttpparam type="Formfield" value="1" name="searchscope">
<cfhttpparam type="Formfield" value="D" name="SORT">
</cfhttp>
<cfoutput>#cfhttp.FileContent#</cfoutput>
<cfdump var="#cfhttp#">
Ian Skinner - 31 Jul 2006 20:04 GMT
Not an easy one.  cfhttp just returns the string of the request.  I
would expect if the javascript was emebed in the HTML they would still
work.  But most likely, the javascript is in another file.  You would
need to make other cfhttp requests to get each javascript file that is
linked.  Then do something with them to make them available to your
local copy of the HTML.  Possible but problematic.

Now if the javascript is simple enough and|or you are motivated enough,
you may be able to do something yourself.  You would have to parse
through the string returned by cfhttp.filecontent and process it in a
similar manner that would happen if the JavaScript was running in a
javascript aware browser.

PS. You probably don't want the <cfdump ...> tag in there forever.  I
just put it in to show you all the information returned in the cfhttp
structure.

> Thanks very much Ian.
>
[quoted text clipped - 17 lines]
>  <cfoutput>#cfhttp.FileContent#</cfoutput>
>  <cfdump var="#cfhttp#">
Ian Skinner - 31 Jul 2006 20:04 GMT
Not an easy one.  cfhttp just returns the string of the request.  I
would expect if the javascript was emebed in the HTML they would still
work.  But most likely, the javascript is in another file.  You would
need to make other cfhttp requests to get each javascript file that is
linked.  Then do something with them to make them available to your
local copy of the HTML.  Possible but problematic.

Now if the javascript is simple enough and|or you are motivated enough,
you may be able to do something yourself.  You would have to parse
through the string returned by cfhttp.filecontent and process it in a
similar manner that would happen if the JavaScript was running in a
javascript aware browser.

PS. You probably don't want the <cfdump ...> tag in there forever.  I
just put it in to show you all the information returned in the cfhttp
structure.

> Thanks very much Ian.
>
[quoted text clipped - 17 lines]
>  <cfoutput>#cfhttp.FileContent#</cfoutput>
>  <cfdump var="#cfhttp#">
Ian Skinner - 31 Jul 2006 20:04 GMT
Not an easy one.  cfhttp just returns the string of the request.  I
would expect if the javascript was emebed in the HTML they would still
work.  But most likely, the javascript is in another file.  You would
need to make other cfhttp requests to get each javascript file that is
linked.  Then do something with them to make them available to your
local copy of the HTML.  Possible but problematic.

Now if the javascript is simple enough and|or you are motivated enough,
you may be able to do something yourself.  You would have to parse
through the string returned by cfhttp.filecontent and process it in a
similar manner that would happen if the JavaScript was running in a
javascript aware browser.

PS. You probably don't want the <cfdump ...> tag in there forever.  I
just put it in to show you all the information returned in the cfhttp
structure.

> Thanks very much Ian.
>
[quoted text clipped - 17 lines]
>  <cfoutput>#cfhttp.FileContent#</cfoutput>
>  <cfdump var="#cfhttp#">
dremmeister - 31 Jul 2006 22:07 GMT
Thanks again Ian, your help is much appreciated.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.