• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Lesson 4. Using Forms with ColdFusion > Displaying Form Variables

Displaying Form Variables

Once a form is submitted, ColdFusion can access the values that the form has passed to it. These values are available to ColdFusion in the form scope. Form variables are just like any other variables; when you set up code for their output, you must enclose them in # signs. Otherwise, you'll see an error message. Form variables must be referenced using the same name they were given in the form. In this form, your variable names are name, email, and comments.

Select File > Open and choose the formoutput.cfm template.

This template is similar to the basicform.cfm template in that all the design features have been set up for you.

After the “thank you” statement, insert the following code:

<cfoutput>Name: #form.name#</cfoutput> 

Use <cfoutput> to let ColdFusion know to process the #form.name# variable. ColdFusion will turn #form.name# into the value that was submitted.


Remember that using the prefix “form” scopes the variable (or narrows the scope of ColdFusion's search). ColdFusion will still work without it, but you will lose a little bit of performance because the program will look through all the variable scopes until it finds a variable called Name.

Continue outputting form variables by adding the following code:

Email: #form.email#<br> 
Comments: #form.comments#


Remember that all ColdFusion variables must be contained in a <cfoutput> tag and be surrounded by # signs to be processed. Otherwise, there is no way for ColdFusion to distinguish variables from regular HTML text.

Your form and output pages are now complete. In order for all this to make sense, it will help for you to try it out for yourself.

Open a browser and type the following URL into the address field:

This brings you to the form that you created earlier in the lesson.

Fill in all the form fields with your information.

Remember, if you leave one of the fields blank you will get an error.

Click Send Comments.

Once you have clicked Send Comments, the form values will be submitted and ColdFusion will process them for display on the next page (the template for which will appear automatically). You should see the values you typed into the form displayed on the page.

Do not close formoutput.cfm or basicform.cfm.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint