
Validating Data Types
91
If the variable is not in a valid date format, an error occurs and the page stops
processing.
Validating form field data types
One limitation of standard HTML forms is that you cannot validate that users input
the type or range of data you expect. ColdFusion enables you to do several types of
data validation by adding hidden fields to forms.
The following table describes the hidden field suffixes that you can use to do
validation:
Note
Adding a validation rule to a field does not make it a required field. You need to add a
separate
_required
hidden field if you want to ensure user entry.
The following procedure creates a simple form for entering a start date and a salary.
It uses hidden fields to ensure that you enter data and that the data is in the right
format.
This example illustrates another concept that might seem surprising. You can use
the same CFML page as both a form page and its action page. Because the only
action is to display the values of the two variables that you enter, the action is on the
same page as the form.
Field Suffix
Value Attribute
Description
_integer
Custom error
message
Verifies that the user entered a number. If the
user enters a floating point value, it is rounded to
an integer.
_float
Custom error
message
Verifies that the user entered a number. Does not
do any rounding of floating point values.
_range
MIN=MinValue
MAX=MaxValue
Verifies that the numeric value entered is within
the specified boundaries. You can specify one or
both of the boundaries separated by a space.
_date
Custom error
message
Verifies that the user entered a date and converts
the date into the proper ODBC date format. Will
accept most common date forms; for example,
9/1/98; Sept. 9, 1998.
_time
Custom error
message
Verifies that the user correctly entered a time and
converts the time to the proper ODBC time
format.
_eurodate
Custom error
message
Verifies that the user entered a date in a standard
European date format and converts into the
proper ODBC date format.
Содержание COLDFUSION 5-DEVELOPING
Страница 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Страница 58: ...38 Chapter 3 Querying a Database ...
Страница 134: ...114 Chapter 7 Updating Your Database ...
Страница 210: ...190 Chapter 10 Reusing Code ...
Страница 232: ...212 Chapter 11 Preventing and Handling Errors ...
Страница 238: ...218 Chapter 12 Using the Application Framework ...
Страница 262: ...242 Chapter 12 Using the Application Framework ...
Страница 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Страница 320: ...300 Chapter 15 Indexing and Searching Data ...
Страница 336: ...316 Chapter 16 Sending and Receiving E mail ...
Страница 374: ...354 Chapter 18 Interacting with Remote Servers ...