MACROMEDIA COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX Getting Started page 100

Building coldfusion mx applications
Table of Contents

Advertisement

Server-side validation approach (no ColdFusion form tag)
The following code is on the server (tripeditaction.cfm page):
<!--- Number of people is Required and must be Numeric --->
<cfif Form.numberPeople EQ "" or IsNumeric(Form.numberPeople) EQ False>
<CFSET IsOk = "No">
<cfoutput>The number of people must be a number and cannot be blank.
</cfoutput>
</cfif>
Code
<cfif Form.numberPeople EQ "" or
IsNumeric(Form.numberPeople) EQ
False>
Client-side validation approach using ColdFusion form tag
The following code is on the client (tripedit.cfm):
<cfinput name="duration" message="Duration must be a number and cannot be
blank."
validate="integer" required="Yes" size="3" maxlength="3">
Code
<cfinput name="duration"
message="Duration must be a number
and
cannot be blank." validate="integer"
required="Yes" size="3"
maxlength="3">
Exercise: modify Trip Edit page to exploit ColdFusion form tags
In this exercise, you will use the ColdFusion form tags to move the validation of many business
rules from the server to the client. To do this, you will change the HTML form tags in the
tripedit.cfm page to ColdFusion form tags that validate these fields on the client side. Next, you
will remove the unneeded server-side single-field validation code from tripeditaction.cfm page.
Finally, you will test the form to ensure the client side validation is working correctly.
To exploit the ColdFusion form tags on the Trip Edit page:
Open the tripedit.cfm in the my_app directory in your editor.
1
Locate and change the
2
Change the <input> tags to
3
the input type for the Submit button must remain a standard input rather than
100
Chapter 8: Lesson 4: Validating Data to Enforce Business Rules
Explanation
The
numberPeople
The
entered on the form was a numeric value.
Explanation
Use the
field within a
field as an
that the field must have an entry. If the data is not
entered or data entered is not an
attribute specifies that the message, "Duration must
be...." appears.
and
<form>
</form>
tags and
<cfinput>
tag evaluates the value of the form variable
cfif
to determine if the user entered a value.
function checks whether the value
IsNumeric
tag to create the
cfinput
. The
cfform
validate
. The
integer
required
tags to
and
<cfform>
tags to
<select>
<cfselect>
input entry
duration
attribute defines the
attribute indicates
, the
integer
message
respectively.
</cfform>,
tags. Note that
.
cfinput

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX and is the answer not in the manual?

This manual is also suitable for:

Coldfusion mx

Table of Contents