
564
Chapter 26: Retrieving and Formatting Data
•
Check boxes, radio buttons, and multiple select boxes do not pass to action pages unless they
are selected on a form. If you try to reference these variables on the action page, you receive an
error if they are not present. For information on how to determine if a variable exists on the
action page, see
“Testing for a variable's existence” on page 566
.
•
You can dynamically populate drop-down lists using query data. For more information, see
“Dynamically populating list boxes” on page 574
.
Working with action pages
A ColdFusion action page is just like any other application page except that you can use the form
variables that are passed to it from an associated form. The following sections describe how to
create effective action pages.
Processing form variables on action pages
The action page gets a form variable for every form control that contains a value when the form is
submitted.
Note:
If multiple controls have the same name, one form variable is passed to the action page with a
comma-delimited list of values.
A form variable's name is the name that you assigned to the form control on the form page. Refer
to the form variable by name within tags, functions, and other expressions on an action page.
Because form variables extend beyond the local page—their scope is the action page—prefix them
with “Form.” to explicitly tell ColdFusion that you are referring to a form variable. For example,
the following code references the LastName form variable for output on an action page:
<cfoutput>
#Form.LastName#
</cfoutput>
The
Form
scope also contains a list variable called
Form.fieldnames
. It contains a list of all form
variables submitted to the action page. If no form variables are passed to the action page,
ColdFusion does not create the
Form.fieldnames
list.
Dynamically generating SQL statements
As described in previous chapters, you can retrieve a record for every employee in a database table
by composing a query like the following:
<cfquery name="GetEmployees" datasource="CompanyInfo">
SELECT FirstName, LastName, Contract
FROM Employee
</cfquery>
But when you want to return information about employees that matches user search criteria, you
use the SQL WHERE clause with a SQL SELECT statement. When the WHERE clause is
processed, it filters the query data based on the results of the comparison.
For example, to return employee data for only employees with the last name of Smith, you build a
query that looks like the following:
<cfquery name="GetEmployees" datasource="CompanyInfo">
SELECT FirstName, LastName, Contract
FROM Employee
WHERE LastName = 'Smith'
</cfquery>
Summary of Contents for COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......