
Validating Data Types
93
</cfoutput>
</cfif>
</html>
3
Save the file as datatest.cfm.
4
View the file in your browser, omit a field or enter invalid data, and click the
Submit button.
When the user submits the form, ColdFusion scans the form fields to find any
validation rules you specified. The rules are then used to analyze the user’s input. If
any of the input rules are violated, ColdFusion sends an error message to the user
that explains the problem. The user then 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 dollar signs, these characters are
automatically deleted from fields with
_integer
,
_float
, or
_range
rules before they
are validated and saved to a database.
Reviewing the code
The following table describes the code and its function:
Code
Description
<form action="actionpage.cfm"
method="post">
Gather the information from this form
using the Post method, and do
something with it on the page
dataform.cfm, which is this page.
<input type="hidden"
name="StartDate_required"
value="You must enter a start date.">
<input type="hidden"
name="StartDate_date"
value="Enter a valid date as the
start date.">
Require input into the StartDate input
field. If there is no input, display the error
information “You must enter a start
date.” Require the input to be in a valid
date format. If the input is not valid,
display 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="hidden"
name="Salary_float"
value="The salary must be a number.">
Require input into the Salary input field.
If there is no input, display the error
information “You must enter a salary.”
Require the input to be in a valid
number. If it is not valid, display the error
information “The salary must be a
number.”
Start Date:
<input type="text"
name="StartDate" size="16"
maxlength="16"><br>
Create a text box called StartDate in
which users can enter their starting date.
Make it exactly 16 characters wide.
Содержание COLDFUSION 5-DEVELOPING
Страница 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Страница 58: ...38 Chapter 3 Querying a Database ...
Страница 134: ...114 Chapter 7 Updating Your Database ...
Страница 210: ...190 Chapter 10 Reusing Code ...
Страница 232: ...212 Chapter 11 Preventing and Handling Errors ...
Страница 238: ...218 Chapter 12 Using the Application Framework ...
Страница 262: ...242 Chapter 12 Using the Application Framework ...
Страница 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Страница 320: ...300 Chapter 15 Indexing and Searching Data ...
Страница 336: ...316 Chapter 16 Sending and Receiving E mail ...
Страница 374: ...354 Chapter 18 Interacting with Remote Servers ...