Home » Tutorials » ColdFusion » Transferring Data

Transferring Data

There are two primary ways to transfer data from page to page in ColdFusion. Embedding a variable in the url, or posting the data with a form are excellent ways to transfer data such as a variable from page to page.

Using Links to Transfer Variables

Links are very effective at this, but please try not to put more than 2 or 3 variables in a link. It is extremely tacky and everyone likes a nice clean url. Below are examples of how to use a link to transfer data.

//Page 1
<a href="test.cfm?myVar=427">Loop Statement</a>
//end Page 1

//Page 2
<cfparam name="myVar" default="" type="integer">

Pretty awesome, huh? You just transfer variable data through a link. ColdFusion is smart enough to understand where the page name ends and the url parameters begin.

The extremely important <cfparam> tag

Go ahead and type some numbers in the url after “myVar=”. If you tried being smart and typing in letters, you should now have an error. The type allowed for our variable was set in the <cfparam> tag. Basically, what happened here was that you put a variable in the url and the <cfparam> tag went looking for anything with the name of myVar to set its value too.There are like 20-30 actual types that the <cfparam> can hold, but here are some of the important ones.

  • boolean
  • integer
  • string
  • list

Of course, Adobe has an awesome tutorials on the <cfparam> tags. Just go to their website, and look it up in the “ColdFusion Tags” section.

Using Forms to Transfer Data

Forms can transfer data in two ways, through a GET or POST action.

GET Request

<cfparam name="getTextBox" default="" type="String">
    <form action="ColdFusionTransferring.cfm" method="get">
        <input name="getTextBox" type="text" value="Type a string here..." onfocus="$(this).val('')"/>
        <input name="" type="submit" value="Submit" />
        You typed: #getTextBox#

Notice how the url has the variable in it after you submit the form because the following POST Request will not. POST Requests are still inside the HTTP Request, but they are not displayed in the url. You can use FireFox’s FireBug or Chrome Developer Tools to see these requests and the post values.

POST Request

<cfparam name="postTextBox" default="" type="String">
    <form action="ColdFusionTransferring.cfm" method="POST">
        <input name="postTextBox" type="text" value="Type a string here..." onfocus="$(this).val('')"/>
        <input name="" type="submit" value="Submit" />
        You typed: #postTextBox#

If you clicked submit on the GET Request and then clicked submit on the POST Request right after, you will notice that the GET Request is actually cleared from the url and doesn’t appear in page. This is because every time we are clicking submit we are sending the forms contents and putting them into temporary variables for the next page. So, when we did the POST request after the GET Request, we lost our GET variables because we weren’t sending them to the next page.

GET/POST Etiquette

So, why don’t we just use GET Requests for everything? I mean it would have the variables up in the url where we could see them. It would help with debugging. While that is great, GET Requests make the url look tacky, and a url can only be so long. That means if you had enough variables in your GET Request to surpass the url length limit, you wouldn’t actually get all of the variables. So, please try to stick with POST requests unless you need the user to be able to show other user’s that specific state through sharing a link. It is recommended that POST Requests are when you want to modify data, and GET Requests are to show data.

Link/cite this page

If you use any of the content on this page in your own work, please use the code below to cite this page as the source of the content.

  • Stewart, Suzy. "Transferring Data". After Hours Programming. Accessed on April 23, 2024. https://www.afterhoursprogramming.com/tutorial/coldfusion/transferring-data/.

  • Stewart, Suzy. "Transferring Data". After Hours Programming, https://www.afterhoursprogramming.com/tutorial/coldfusion/transferring-data/. Accessed 23 April, 2024.

  • Stewart, Suzy. Transferring Data. After Hours Programming. Retrieved from https://www.afterhoursprogramming.com/tutorial/coldfusion/transferring-data/.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.