Skip to main content
Known Participant
December 21, 2010
Question

passing form variables to another website

  • December 21, 2010
  • 3 replies
  • 653 views

Hi,

Basically, I want to pass form variables to another website for continous 5 times, what's the best way to do this?  Here is the sample code.  So the form will submit 5 times to the action website

<cfloop from="1" to="5" index="index">

     <form action="http://www.website.com/info.cfm" method="post" id="frmname" name="frmname">

          <input type="hidden" name="name" value="name1" />

          <input type="hidden" name="id" value="#index#" />

          <input type="hidden" name="test" value="test tex" />

     </form>

<script language=javascript>

document.frmname.submit();

</script>

</cfloop>

    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    December 24, 2010

    Like 12Robots and Ilssac I too thought of the cfhttp tag. However, I also thought you might want to supply the variables dynamically, for example, like this

    <cfset name = arrayNew(1)>
    <cfset id   = arrayNew(1)>
    <cfset test = arrayNew(1)>

    <cfset name[1] = "blah_di_blah">
    <cfset name[2] = "second_blah_di_blah">
    ...
    etc., etc.
    ...
    <cfset test[4] = "fourth text">
    <cfset test[5] = "fifth text">

    <cfloop from="1" to="5" index="idx">
         <cfhttp url="http://www.website.com/info.cfm" method="post">
              <cfhttpparam type="formfield" name="name" value="#name[idx]#" />
              <cfhttpparam type="formfield" name="id" value="#id[idx]#" />
              <cfhttpparam type="formfield" name="test" value="#test[idx]#" />
         </cfhttp>
    </cfloop>

    ilssac
    Inspiring
    December 21, 2010

    12robots beat me to the answer.

    But to expand on it a bit.  Your original code would have output HTML form code five times, most likely to the user's browser client that requested the URL that executes that code.  This would do nothing to actually submit the forms and their data.  A user would have to have done it.

    As noted in the previous post, the <cfhttp....> tag is designed to make HTTP requests of other servers, allowing ColdFusion to act as a client which is normally the role of the user's browser.

    12Robots
    Participating Frequently
    December 21, 2010

    Might this work for you?

    <cfloop from="1" to="5" index="index">
         <cfhttp url="http://www.website.com/info.cfm" method="post">
              <cfhttpparam type="formfield" name="name" value="name1" />
              <cfhttpparam type="formfield" name="id" value="#index#" />
              <cfhttpparam type="formfield" name="test" value="test tex" />
         </cfhttp>
    </cfloop>