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.
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.
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.
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.
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.
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.