8 Replies Latest reply on Jul 31, 2006 2:07 PM by dremmeister

    Emulating Form Post

    dremmeister
      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.
        • 1. Re: Emulating Form Post
          Level 7
          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.



          dremmeister wrote:
          > 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.
          >
          • 2. Re: Emulating Form Post
            dremmeister Level 1
            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.
            • 3. Re: Emulating Form Post
              Level 7
              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.


              dremmeister wrote:
              > 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.
              >
              • 4. Re: Emulating Form Post
                dremmeister Level 1
                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#">
                • 5. Re: Emulating Form Post
                  Level 7
                  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.



                  dremmeister wrote:
                  > 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#">
                  >
                  >
                  • 6. Re: Emulating Form Post
                    Level 7
                    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.



                    dremmeister wrote:
                    > 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#">
                    >
                    >
                    • 7. Re: Emulating Form Post
                      Level 7
                      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.



                      dremmeister wrote:
                      > 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#">
                      >
                      >
                      • 8. Re: Emulating Form Post
                        dremmeister Level 1
                        Thanks again Ian, your help is much appreciated.