MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 580

Developing coldfusion mx applications
Table of Contents

Advertisement

To validate the data that users enter in the insert form:
Create a new page with the following text:
1
<html>
<head>
<title>Simple Data Form</title>
</head>
<body>
<h2>Simple Data Form</h2>
<!--- Form part --->
<form action="datatest.cfm" method="Post">
<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.">
<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.">
Start Date:
<input type="text"
name="StartDate" size="16"
maxlength="16"><br>
Salary:
<input type="text"
name="Salary"
size="10"
maxlength="10"><br>
<input type="reset"
name="ResetForm"
value="Clear Form">
<input type="submit"
name="SubmitForm"
value="Insert Data">
</form>
<br>
<!--- Action part --->
<cfif isdefined("Form.StartDate")>
<cfoutput>
Start Date is: #DateFormat(Form.StartDate)#<br>
Salary is: #DollarFormat(Form.Salary)#
</cfoutput>
</cfif>
</html>
Save the file as datatest.cfm.
2
View the file in your browser, omit a field or enter invalid data, and click the Submit button.
3
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.
580
Chapter 26: Retrieving and Formatting Data

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents