Adobe COLDFUSION 9 Manual page 764

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Because numeric values often contain commas and currency symbols, ColdFusion automatically deletes these
characters from fields with _cfforminteger and _cfformfloat rules before it validates the form field and passes the data
to the form's action page. ColdFusion does not delete these characters from fields with _cfformnumeric rules.
Reviewing the code
The following table describes the code and its function:
Code
<form action="datatest.cfm" method="Post">
<input type="hidden"
name="StartDate_cfformrequired" value="You
must enter a start date.">
<input type="hidden"
name="StartDate_cfformdate" value="Enter a
valid date as the start date.">
<input type="hidden"
name="Salary_cfformrequired" value="You
must enter a salary.">
<input type="hidden"
name="Salary_cfformfloat" value="The
salary must be a number.">
Start Date:
<input type="text" name="StartDate"
size="16" maxlength="16"><br>
Salary:
<input type="text" name="Salary" size="10"
maxlength="10"><br>
<cfif isdefined("Form.StartDate")>
<cfoutput>
Start Date is:
#DateFormat(Form.StartDate)#<br>
Salary is: #DollarFormat(Form.Salary)#
</cfoutput>
</cfif>
Validating form input and handling errors with JavaScript
ColdFusion lets you write your own validation routines in JavaScript, and lets you create JavaScript error handlers.
Validating input with JavaScript
In addition to native ColdFusion input validation using the
the following tags support the
input validation:
cfform
cfgrid
cfinput
cfslider
cftextarea
cftree
ColdFusion passes the following arguments to the JavaScript function that you specify in the
• The form JavaScript DOM object
Description
Gathers the information from this form sends it to the dataform.cfm page (this
page) using the Post method.
Requires input into the StartDate input field. If there is no input, displays the error
information "You must enter a start date." Requires the input to be in a valid date
format. If the input is not valid, displays the error information "Enter a valid date as
the start date."
Requires input into the Salary input field. If there is no input, displays the error
information "You must enter a salary." Requires the input to be in a valid number.
If it is not valid, displays the error information "The salary must be a number."
Creates a text box called StartDate in which users can enter their starting date.
Makes it 16-characters wide.
Creates a text box called Salary in which users can enter their salary. Makes it ten-
characters wide.
Displays the values of the StartDate and Salary form fields only if they are defined.
They are not defined until you submit the form, so they do not appear on the initial
form. Uses the DateFormat function to display the start date in the default date
format. Uses the DollarFormat function to display the salary with a dollar sign and
commas.
attribute, which lets you specify a JavaScript function to handle your
onValidate
Last updated 8/5/2010
attribute of the
validate
cfinput
759
and
tags,
cftextarea
attribute:
onValidate

Advertisement

Table of Contents
loading

Table of Contents