Skip to main content
BurtleEd
Known Participant
March 15, 2010
Answered

Auto complete a form with Coldfusion 8

  • March 15, 2010
  • 2 replies
  • 6126 views

We have a site that we utilize at http://ondemand.nssl.noaa.gov/ and select at fill out the same items every time is there a way to automate this. If so how can I get ColdFusion 8 to go to the site and fill out this form and submit it. We have permission from the owner to do this from our IP address.

    This topic has been closed for replies.
    Correct answer ilssac

    Yeah, I remember...but...I thought once you made it to the confirm.php page you would then be given the link to download the zip. Instead it give you a random link to another page when the zip file can be downloaded. Pain in the butt.

    I found some code you had created a while back on another post that finds the random url on the page and goes to it but the error on the previous post is what I get when I try to run it.


    I used this code to successfully download a zip file.

    <cfhttp url="http://ondemand.nssl.noaa.gov/tmp/COQ639YMTSR5/COQ639YMTSR5.zip"
    getAsBinary="yes" path="C:\Inetpub\wwwroot\" file="theZipfile.zip">

    <cfdump var="#cfhttp#">

    But when I went to the website to generate that file, I did not get a webpage the listed it, I got an email that sent me to a web page that listed it.  Is that the way it works for you as well?

    2 replies

    BurtleEd
    BurtleEdAuthor
    Known Participant
    March 17, 2010

    Alright, I think I'm close. The url on the confirm.php page is http://ondemand.nssl.noaa.gov/index.php?category=tmp/T12125ZILK/index.php

    So I added the code below, but here is the error I'm getting.

    Code

    <!---Start to find url --->
    <cfif myform.filecontent >
    <cfloop query="myform">
           Get the content of the message, assuming there's a plain text part
            <cfset thisContent = myform.filecontent />
           
             Find the index of the string starting "http://"
            <cfset httpIndexChar = find("http://",thisContent) />
             Find the index of the word ".php" and add four to *include* the ".php"
            <cfset firstPhpIndexChar = find(".php",thisContent) + 4 />
             Do the same again from that point, as the URL has two ".php" parts
            <cfset secondPhpIndexChar = find(".php",thisContent,firstPhpIndexChar) + 4 />
             Calculate the length of the URL, so we can strip it out
            <cfset urlLength = secondPhpIndexChar - httpIndexChar >
             Strip down the message content to only the characters between those two values,
            this should now be the valid URL
            <cfset theURL = mid(thisContent,httpIndexChar,urlLength) />
             Create an HTTP connection to the URL and get back a struct of its content          
            <cfhttp url="#theUrl#" result="httpContent"/>
            </cfloop>
            </cfif>

    <cfoutput>#httpContent.filecontent#</cfoutput>

    This is the error

    cannot convert the value " 0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d)&&d.all) x=d.all; for (i=0;!x&&i

    ilssac
    Inspiring
    March 17, 2010

    Remember what I said in an earlier post that there is a difference between an HTTP get request for a text file like HTML and an HTTP get request for a binary file like a ZIP file.  The <cfhttp...> documention provides good information on how to handle both types of requests.

    BurtleEd
    BurtleEdAuthor
    Known Participant
    March 17, 2010

    Yeah, I remember...but...I thought once you made it to the confirm.php page you would then be given the link to download the zip. Instead it give you a random link to another page when the zip file can be downloaded. Pain in the butt.

    I found some code you had created a while back on another post that finds the random url on the page and goes to it but the error on the previous post is what I get when I try to run it.

    ilssac
    Inspiring
    March 15, 2010

    If you want ColdFusion to dynamically submit form data to another webserver, you would use the <cfhttp....> and <cfhttpparam...> tags to do that.

    With these tags you can define the various form fields and their values and submit it to the other server and the receive the response in a variable for further processing.

    You could also use the <cfhttp....> tag to fetch the form for processing if it is something you feel needs to be done dynamically, but it is beyond the scope of a simple forum response to describe how to parse up the result and dynamically build a new <cfhttp....> request out of the results.

    BurtleEd
    BurtleEdAuthor
    Known Participant
    March 15, 2010

    I am a little new to CF8 can you get me started if possible? I am a pretty fast learner if I see what going on.

    ilssac
    Inspiring
    March 15, 2010

    Assuming you wanted to submit an http form request to the url http:///www.aServer.com/theForm.html that had this form on it.

    <form...>

      <input type="text" name="yourName"...>

      <input type="text" name="favColor"...>

    </form>

    You could is something like this with your ColdFusion CFML.

    <cfhttp url="http://www.aServer.com/theForm.html" result="myVariable">
      <cfhttpparam name="yourName" value="George Forman" type="formfield">
      <cfhttpparam name="favColor" value="Green" type="formField">
    </cfhttp>

    <cfdump var="#myVariable#">

    But the documentation has much more complete examples and descriptions.

    http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_g-h_09.html

    http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec1529c-7ff3.html