ColdFusion form tags include the following attributes:
Attribute
Description
validate
The data type that the field tag validates against. Values include: integer, date, time,
telephone, zipcode.
message
The error message that appears if validation fails.
range
The range of permissible values for this tag.
required
An indicator of whether data is required for the corresponding tag.
To use the improved form tags, you must replace the HTML form tag with the
following code snippets show the use of the improved ColdFusion form tags. The first code
snippet shows how the duration field is validated on the server. The second code snippet shows
how ColdFusion form tags simplify field validation on the client.
Server-side validation approach (no cfform 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 a cfform tag
The following code is on the client (tripedit.cfm page):
<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">
Explanation
The
cfif
numberPeople
The
IsNumeric
entered on the form was a numeric value.
Explanation
Use the
field within a
the field as an
that the field must have an entry. If the data is not
entered or data entered is not an integer, the
attribute specifies that the message, "Duration must
be...." appears.
Exercise 5: Validating data on the client using ColdFusion form tags
tag evaluates the value of the form variable
to determine if the user entered a value.
function checks whether the value
tag to create the
cfinput
tag. The
cfform
validate
. The
integer
required
tag. The
cfform
input entry
duration
attribute defines
attribute indicates
message
115
Need help?
Do you have a question about the COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION MX and is the answer not in the manual?
Questions and answers