Displaying Form Variables

I l @ ve RuBoard

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.

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

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

    TIP

    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.

  3. Continue outputting form variables by adding the following code:

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

    TIP

    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.

  4. Open a browser and type the following URL into the address field: http://127.0.0.1/Lesson4/Start/basicform.cfm .

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

  5. Fill in all the form fields with your information.

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

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

I l @ ve RuBoard


Macromedia ColdFusion 5. Training from the Source
Macromedia ColdFusion 5 Training from the Source (With CD-ROM)
ISBN: 0201758474
EAN: 2147483647
Year: 2002
Pages: 99
Authors: Kevin Schmidt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net