Passing Parameters Via URL

One way to pass data from one template to the next is through hyperlinks containing special URL parameters. The HTTP specification allows you to append parameters to the end of a URL in the format:

            filename.cfm?param1=value1&param2=value2&param3=value3

The question mark immediately following the extension of the template in the URL specifies the beginning point for appending URL parameters. Each URL parameter consists of a parameter name followed by an equal sign, then the value assigned to the parameter. You can append more than one URL parameter to a URL by delimiting them with ampersands. Note that no spaces may appear in the URL string unless they are escaped first (see “Dealing with Special Characters”).

When you click on a hyperlink containing one or more URL parameters, those parameters are automatically sent to the template specified in the URL of the link and thus are available to the template as URL variables. The following example illustrates how URL variables are passed from template to template in ColdFusion. The first template, shown in Example 3-1, creates several ColdFusion variables and appends them and their associated values to a URL.

Example 3-1. Creating URL parameters

<!--- Set variables to be passed to another template ---> <cfset x=1> <cfset color="green"> <cfset Pass = True> <h2>Passing Data via URL Parameters</h2> <!--- Create a hyperlink containing URL parameters ---> <cfoutput> <a href="receiveurlparameters.cfm?x=#x#&color=#color#&pass=#pass#">Click ...

Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.