User Guide

Table Of Contents
Validating form data using hidden fields 679
</cfif>
</html>
When the user submits this form, ColdFusion scans the form fields to find any validation rules. It
then uses the rules to analyze the users input. If any of the input rules are violated, ColdFusion
displays an error page with the error message that you specified in the hidden field’s
value
attribute. The user must go back to the form, correct the problem, and resubmit the form.
ColdFusion does not accept form submission until the user enters the entire form correctly.
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 Description
<form action="datatest.cfm"
method="post">
Gathers the information from this form sends it to
the dataform.cfm page (this page) using the Post
method.
<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.">
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.”
<input type="hidden"
name="Salary_required"
value="You must enter a salary.">
<input type="cfformhidden"
name="Salary_cfformfloat"
value="The salary must be a number.">
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.”
Start Date:
<input type="text"
name="StartDate" size="16"
maxlength="16"><br>
Creates a text box called StartDate in which users
can enter their starting date. Makes it 16-
characters wide.
Salary:
<input type="text"
name="Salary"
size="10"
maxlength="10"><br>
Creates a text box called Salary in which users can
enter their salary. Makes it ten-characters wide.
<cfif isdefined("Form.StartDate")>
<cfoutput>
Start Date is:
#DateFormat(Form.StartDate)#<br>
Salary is:
#DollarFormat(Form.Salary)#
</cfoutput>
</cfif>
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.