
751
DEVELOPING
COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Las
t
upda
te
d 8/5/2010
3
For HTML and XML format forms (using ColdFusion skins), most ColdFusion form tags have an
onError
attribute that lets you specify a Javascript function to run if an onSubmit error occurs.
4
For the
IsValid
function, you write separate code paths to handle valid and invalid data. The following example
shows a simplified case that displays an error message if the user entered an invalid e-mail address, or a different
message if the address is valid:
<cfif IsValid("email", custEmail)>
Thank you for entering a valid address.
<!--- More processing would go here. --->
<cfelse>
You must enter a valid e-mail address.<br>
Click the Back button and try again.
</cfif>
5
For
cfparam
and
cfargument
tags, you use standard ColdFusion error-handling techniques. You can include the
tag in a
try
block and use a
catch
block to handle the error, or you can use a custom error-handling page. The
following example form action page code uses a custom error page, expresserr.cfm, to handle the error that the
cfparam
tag generates if a user submits a form with an invalid e-mail address:
<cferror type="EXCEPTION" exception="expression" template="expresserr.cfm">
<cfif IsDefined("form.fieldnames")>
<cfparam name="form.custEmail" type="email">
<!--- Normal form processing code goes here. --->
</cfif>
Masking form input values
The
cfinput
tag
mask
attribute controls the format of data that can be entered into a
text
or
datefield
input field.
You can also use a mask attribute in the
cfcalendar
tag. You can combine masking and validation on a field.
•
In HTML and Flash form format, a mask can control the format of data entered into a
text
field.
•
In the
cfcalendar
tag, and, for Flash format forms, the
datefield
type
cfinput
field, a mask can control the
format of the date that ColdFusion uses for the date a user chooses in the displayed calendar.
Note:
The standard ColdFusion XML skins do not support masking.
Masking text input
In text fields, ColdFusion automatically inserts literal mask characters, such as - characters in telephone numbers.
Users type only the variable part of the field. You can use the following characters to mask data:
The following pattern enforces entry of a part number of the format EB-1234-c1-098765, where the user starts the
entry by typing the first numeric character, such as 1. ColdFusion fills in the preceding EB prefix and all hyphen (-)
characters. The user must enter four numbers, followed by two alphanumeric characters, followed by six numbers.
<cfinput type="text" name="newPart" mask="EB-9999-XX-999999" />
Mask character
Effect
A
Allows an uppercase or lowercase character: A–Z and a–z.
X
Allows an uppercase or lowercase character or number: A–Z, a–z, and 0–9.
9
Allows a number: 0–9.
?
Allows any character.
All other characters
Automatically inserts the literal character.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...