
755
DEVELOPING
COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Las
t
upda
te
d 8/5/2010
Note:
An excellent reference on regular expressions is Mastering Regular Expressions by Jeffrey E.F. Friedl, published by
O'Reilly & Associates, Inc.
Validating form data using hidden fields
ColdFusion lets you specify form field validation on the server by using hidden form fields whose names consist of the
name of the field to validate and the validation type. Hidden field validation uses the same underlying techniques and
algorithms as onServer validation of ColdFusion form fields.
Hidden field validation has the following features:
•
You can use it with standard HTML tags. For example, you can validate data in an HTML
input
tag. This feature
was useful in releases previous to ColdFusion MX 7, because the
cfinput
tag did not support all HTML
type
attributes.
•
It is backward-compatible with validation previous to ColdFusion MX 7, when hidden field validation was the only
way to do validation on the server.
•
Because you use a separate tag for each validation type, if you specify multiple validation rules for a field, you can
specify a different error message for each rule.
•
You can use hidden field validation with any form field type that submits a data value, not
input
,
cfinput
,
textarea
, or
cftextarea.
Specifying hidden form field validation
To specify hidden field validation, you do the following:
•
Create one HTML
input
element or CFML
cfinput
tag of
type="hidden"
for each validation rule.
•
Specify the name of the field to validate as the first part of the hidden field name.
•
Specify the type of validation, starting with an underscore character (_), as the second part of the hidden field name.
•
You can specify multiple rules for each form data field. For example, to specify range and required validation for a
field named myValue, create hidden myValue_cfformrange and myValue_cfformrequired fields.
•
For most types of validation, specify the error message as the field
value
attribute.
•
For range, maximum length, or regular expression validation, specify the rule, such as the maximum length, in the
value
attribute. For these validation types, you cannot specify a custom error message.
The following example uses hidden fields to require data in a date field and ensure that the field contains a date. It
consists only of HTML tags.
Expression
Description
[\?&]value=
Any string containing a URL parameter value.
^[A-Z]:(\\[A-Z0-9_]+)+$
An uppercase Windows directory path that is not the root of a drive and has only letters,
numbers, and underscores in its text.
^(\+|-)?[1-9][0-9]*$
An integer that does not begin with a zero and has an optional sign.
^(\+|-)?[1-9][0-9]*(\.[0-9]*)?$
A real number.
^(\+|-)?[1-9]\.[0-9]*E(\+|-)?[0-9]+$
A real number in engineering notation.
a{2,4}
A string containing two to four occurrences of
a
: aa, aaa, aaaa; for example, aardvark, but not
automatic.
(ba){2,}
A string containing least two
ba
pairs; for example, Ali baba, but not Ali Baba.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...