User Guide

Table Of Contents
Validating data with the IsValid function and the cfparam tag 683
Minimum Quantity: <cfinput type="Text" name="MinQuantity"
onError="showErrorMessage" validate="numeric" required="Yes"
message="is not a number." ><br>
<!--- A maximum quantity is optional, but must be a number if supplied. --->
Maximum Quantity: <cfinput type="Text" name="MaxQuantity"
onError="showErrorMessage" validate="numeric"
message="is not a number." ><br>
<cfinput type="submit" name="submitit">
</cfform>
Validating data with the IsValid function and the cfparam tag
The IsValid function and cfparam tag validate any ColdFusion MX variable value, not just
forms variables. Because they reside entirely on the ColdFusion server, they can provide a secure
mechanism for ensuring that the required validation steps get performed. Users cannot evade any
of the checks by modifying the form data that gets submitted. These techniques also provide
greater flexibility in how you respond to user errors, because you can use full CFML syntax in
your error-handling code.
These two validation techniques operate as follows:
The IsValid function tests the value of a ColdFusion variable. If the value is valid, it returns
True; if the value is invalid, it returns False.
The cfparam tag with a type attribute tests the value of a ColdFusion value for validity. If the
value is valid, it does nothing; if the value is invalid, it throws a ColdFusion expression
exception.
You can use either technique interchangeably. The one you choose should depend on your coding
style and programming practices. It can also depend on the specific information that you want to
display if an error occurs.
Example: IsValid function validation
The following example checks whether a user has submitted a numeric ID and a valid e-mail
address and phone number. If any of the submitted values does not meet the validation test, the
page displays an error message.
<!--- Action code. First make sure the form was submitted. --->
<cfif isDefined("form.saveSubmit")>
<cfif isValid("integer", form.UserID) and isValid("email", form.emailAddr)
and isValid("telephone", form.phoneNo)>
<cfoutput>
<!--- Application code to update the database goes here --->
<h3>The e-mail address and phone number for user #Form.UserID#
have been added</h3>
</cfoutput>
<cfelse>
<H3>Please enter a valid user ID, phone number, and e-mail address.</H2>
</cfif>
<cfelse>
</cfif>
<!--- The form. --->