
750
DEVELOPING
COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Las
t
upda
te
d 8/5/2010
<cfif IsDefined("form.fieldnames")>
<cfdump var="#form#"><br>
</cfif>
<cfform name="myform" preservedata="Yes" >
First Name: <cfinput type="text" size="15" name="firstname"
required="yes" message="You must enter a first name."><br>
Last Name: <cfinput type="text" size="25" name="lastname"
required="yes" message="You must enter a last name."><br>
Telephone: <cfinput type="text" size="20" name="telephone"
validate="telephone" message="You must enter your telephone
number, for example 617-555-1212 x1234"><br>
E-mail: <cfinput type="text" size="25" name="email"
validate="email" required="Yes"
message="You must enter a valid e-mail address."><br>
Password:<cfinput type="password" size="12" name="password1"
required="yes" maxlength="12"
message="You must enter a password."><br>
Reenter password:<cfinput type="password" size="12" name="password2"
required="yes" maxlength="12"
message="You must enter your password twice."><br>
We will ask you for the following number, in the range 100-999 if you forget
your password.<br>
Number: <cfinput type="text" size="5" name="chalenge"
validate="range" range="100,999" required="Yes"
message="You must enter a reminder number in the range 100-999."><br>
<cfinput type="submit" name="submitit">
</cfform>
Handling invalid data
How you handle invalid data depends on the validation type. The information here describes validation error-
handling rules and considerations. For detailed information on error handling in ColdFusion, including invalid data
handling, see “
Handling Errors
” on page 275.
1
For onBlur, onSubmit, or onServer validation, you can use the
cfinput
or
cftextarea
tag’s
message
attribute to
specify a text-only error message to display. Otherwise, ColdFusion uses a default message that includes the name
of the form field that was invalid. (For OnServer validation, you can customize this message, as described in
“
Handling form field validation errors
” on page 282.) The following example displays an error message when the
user enters an invalid e-mail address:
E-mail: <cfinput type="text" size="25" name="email"
validate="email" message="You must enter a valid e-mail address.">
2
For hidden form validation, you can specify a text-only error message in the hidden field’s
value
attribute.
Otherwise, ColdFusion uses a default message that includes the name of the form field that was invalid. (You can
customize this message, as described in “
Handling form field validation errors
” on page 282.) The following
cfinput
tag, for example, uses a hidden field validation to display an error message if the user enters an invalid
address. (It uses onServer validation to display a different error message if the user fails to enter a number.)
Telephone: <cfinput type="text" size="20" name="telephone"
validateat="onServer" required="Yes"
message="You must enter a telephone number">
<cfinput type="hidden" name="telephone_cfformtelephone"
value="The number you entered is not in the correct format.<br>Use a
number such as (617) 555-1212, 617-555-1212, or 617-555-1212 x12345">
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...