Creating Action Pages - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

However, instead of putting the LastName directly in the SQL WHERE clause, you can use the
text that the user entered in the form for comparison:
<cfquery name="GetEmployees" datasource="CompanyInfo">
SELECT FirstName, LastName, Salary
FROM Employee
WHERE LastName=<cfqueryparam value="#Form.LastName#"
CFSQLType="CF_SQL_VARCHAR">
</cfquery>
For security, this example encapsulates the form variable within the
that the user passed a valid string value for the LastName. For more information on using the
tag with queries and on Dynamic SQL, see
cfqueryparam
Data," on page
427.

Creating action pages

Use the following procedure to create an action page for the page formpage.cfm that you created
in the previous example.
To create an action page for the form:
Create a ColdFusion page with the following content:
1
<html>
<head>
<title>Retrieving Employee Data Based on Criteria from Form</title>
</head>
<body>
<cfquery name="GetEmployees" datasource="CompanyInfo">
SELECT FirstName, LastName, Salary
FROM Employee
WHERE LastName=<cfqueryparam value="#Form.LastName#"
CFSQLType="CF_SQL_VARCHAR">
</cfquery>
<h4>Employee Data Based on Criteria from Form</h4>
<cfoutput query="GetEmployees">
#FirstName#
#LastName#
#Salary#<br>
</cfoutput>
<br>
<cfoutput>Contractor: #Form.Contractor#</cfoutput>
</body>
</html>
Save the page as actionpage.cfm within the myapps directory.
2
View formpage.cfm in your browser.
3
Enter data, for example, Smith, in the Last Name box and submit the form.
4
The browser displays a line with the first and last name and salary for each entry in the
database that match the name you typed, followed by a line with the text "Contractor: Yes"
Click Back in your browser to redisplay the form.
5
Remove the check mark from the check box and submit the form again.
6
This time an error occurs because the check box does not pass a variable to the action page. For
information on modifying actionpage.cfm to fix the error, see
existence" on page
566.
cfqueryparam
Chapter 20, "Accessing and Retrieving
"Testing for a variable's
Working with action pages
tag to ensure
565

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents