Programming instructions

26 Chapter 2 CFML Basics
Using cfelseif to evaluate multiple expressions
To evaluate multiple expressions in a cfif statement, you can use cfelseif and cfelse
in your statement, for example:
<cfif expression 1>
HTML and CFML tags executed if expression 1 is True.
<cfelseif expression 2>
HTML and CFML tags executed if expression 2 is True.
<cfelse>
HTML and CFML tags executed for expression(s) that is False.
</cfif>
The following example shows you how you can evaluate multiple expressions using these
tags. In this example, you created a form in which users can enter their state to determine
their state tax:
<cfoutput>
<cfif form.state IS "MA">
#form.state# State Tax: 8.5%
<cfelseif form.state IS "VA">
#form.state# State Tax: 8.2%
<cfelse>
#form.state# State Tax Unknown
</cfif>
</cfoutput>
The output of this cfif statement is based on the value entered by the user. If the user
enters MA in the state form field, the state tax results returned is 8.5%. If the user enters
VA in the state form field, the state tax results returned is 8.2%. If the user enters any
other state in the state form field, State Tax Unknown is returned.
Processing form data
Virtually all web applications that gather and write information to a database use a form
to accomplish that task. Forms let you collect information from a user (using an order
form, registration form, and so on) and write that information to a database. Like
HTML, there are two independent steps for creating a form in ColdFusion:
1 Creating the layout for the form itself.
2 Writing the code to process the submitted information.
Form processing
Every form that you create in ColdFusion consist of two parts: the form page and the
action page.These two pages work together to process user input. The form page
contains the user interface elements, such as input fields, and radio buttons. The action
page handles the processing of the form page data.