Validating Data - Adobe 38043740 - ColdFusion Standard - Mac Development Manual

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
For example, the following
cfparam
RowsToFetch:
<cfparam name="Form.StartRow">
<cfparam name="Form.RowsToFetch">
If the page with these tags is called without either one of the form variables, an error occurs and the page stops
processing. By default, ColdFusion displays an error message; you can also handle the error as described in
Errors" on page 275.
Example: setting default values
The following example uses the
they do not exist, the ColdFusion server creates them and sets them to the default values.
<cfparam name="Cookie.SearchString" default="temple">
<cfparam name="Client.Color" default="Gray">
<cfparam name="ShowExtraInfo" default="No">
You can use the
tag to set default values for URL and Form variables, instead of using conditional logic. For
cfparam
example, you could include the following code on the action page to ensure that a SelectedDepts variable exists:
<cfparam name="Form.SelectedDepts" default="Marketing,Sales">

Validating data

It is often not sufficient that input data merely exists; it must also have the right format. For example, a date field must
have data in a date format. A salary field must have data in a numeric or currency format. There are many ways to
ensure the validity of data, including the following methods:
• Use the
tag with the
cfparam
• Use the IsValid function to validate a variable.
• Use the
tag in a SQL WHERE clause to validate query parameters.
cfqueryparam
• Use
controls that have validation attributes.
cfform
• Use a form
tag with a
input
Note: Data validation using the
tags and hidden fields is done using JavaScript in the user's browser, before any data is sent to the server.
For detailed information on validating data in forms and variables, see
information on validating query parameters, see
Passing variables to custom tags and UDFs
The following sections describe rules for how data gets passed to custom tags and user-defined functions that are
written in CFML, and to CFX custom tags that are written in Java or C++.
Passing variables to CFML tags and UDFs
When you pass a variable to a CFML custom tag as an attribute, or to a user-defined function as an argument, the
following rules determine whether the custom tag or function receives its own private copy of the variable or only gets
a reference to the calling page's variable:
• Simple variables and arrays are passed as copies of the data. If your argument is an expression that contains multiple
simple variables, the result of the expression evaluation is copied to the function or tag.
tags indicate that this page expects two form variables named StartRow and
tag to see if optional variables exist. If they do exist, processing continues. If
cfparam
attribute to validate a variable.
type
attribute to validate the contents of a form input field.
hidden
, and
cfparam,cfqueryparam
"Using
cfqueryparam" on page 416.
Last updated 1/20/2012
tags is done by the server. Validation using
form
"Validating
Data" on page 743 For detailed
63
"Handling
cfform

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents