Skip to main content
Participating Frequently
August 2, 2011
Question

Emulate a form post with ColdFusion

  • August 2, 2011
  • 3 replies
  • 6953 views

I am trying to emulate a form post that the browser actually redirects using only ColdFusion.  So essentially I am trying to emulate a form post like:

<form id="BMLForm" action="https://mit.securecheckout.billmelater.com/paycapture-ws/paycapturelite" method="POST">

      <input type="hidden" name="aMid" value="12345678"/>

      <input type="hidden" name="amt" value="1.00"/>

      <input type="hidden" name="bName" value="Test Name"/>

      <input type="hidden" name="bAddr1" value="Test 123"/>

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

      <input type="hidden" name="bCity" value="Omaha"/>

      <input type="hidden" name="bState" value="NE"/>

      <input type="hidden" name="bZip" value="68104"/>

      <input type="hidden" name="email" value="test@Test.com"/>

      <input type="hidden" name="phone" value="4029171234"/>

      <input type="hidden" name="iUrl" value="http://www.mywebsite.com/page.cfm" />

      <input type="hidden" name="updUrl" value="http://www.mywebsite.com/page.cfm"/>

      <input type="hidden" name="mpUrl" value=" http://www.mywebsite.com/page.cfm"/>

      <input type="hidden" name="logoUrl"/>

      <input type="submit" name="mRefId"/>

</form>

It should happen only in ColdFusion.  I tried cfhttp but that does not actually redirect the customer via the browser.  It just gives you the html output.  cflocation but that is only a get.

So essentially we need to emulate a form post only using coldfusion.  No actual form, html, or javascript.

The same as cflocation can emulate a form get.

Thanks

    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    August 3, 2011

    corradodev wrote:

    The same as cflocation can emulate a form get.

    Do you mean something like this?

    <form action="action1.cfm" method="get">

    <input name="field" type="text">

    <input name="sbmt" type="submit" value="Submit">
    </form>

    action1.cfm

    <cflocation url="action2.cfm">

    I ask because I don't think that the form variables will be available in action2.cfm.

    Participating Frequently
    August 3, 2011

    I want a form post instead of a get.  So if your using something like firebug or something that sniffs the headers it will post data to a url.

    cflocation has no way to do a post method that I have found.

    You could from your example dynamically create the query string to make it a get to action2.cfm.  But I am trying to do a post

    BKBK
    Community Expert
    Community Expert
    August 3, 2011
    ... the browser actually redirects ... redirect the customer via the browser.

    I am uncomfortable with these choice of words. The browser does not redirect; it is redirected.

    Participating Frequently
    August 3, 2011

    Sorry for any confusion this caused BKBK.

    I was just trying to differentiate between just getting the html back like cfhttp would and actually redirecting the customer.  I will try to be clearer for future posts.

    Participant
    August 3, 2011

    Hi,

    Take a look at getPageContext().forward()

    and

    http://download.oracle.com/javaee/5/api/javax/servlet/jsp/PageContext.html#forward%28java.lang.String%29

    In essence, you forward the post sent by the browser to another cfm template.

    That cfm template gets executed and it's output is sent to the browser as response.

    Participating Frequently
    August 3, 2011

    It looks like that just does a get and not a post unless I am mistaken.  Can you give me an example of a post if I am wrong.

    Owainnorth
    Inspiring
    August 3, 2011

    I do not believe you can use CF to force a POST from someone's browser, if that's what you mean. The closest you could do is use CFHTTP to do the actual POST, then display the HttpContent variable back to them. However all you're really doing is a POST from the server, scraping the output and returning it to them, which is slightly different.

    I think you'd need to use JavaScript to get their browser to actually post to a page, because it requires a web request with a completely different method attribute.