Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 769

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
<!--- Action part of the page. --->
<!--- If an expression exception occurs, run the expresser.cfm page. --->
<cferror type="EXCEPTION" exception="expression" template="expresserr.cfm">
<!--- Make sure the form was submitted. --->
<cfif isDefined("form.saveSubmit")>
<!--- Use cfparam tags to check the form field data types. --->
<cfparam name="form.emailAddr" type="email">
<cfparam name="form.UserID" type="integer">
<cfparam name="form.phoneNo" type="telephone">
<!--- Application code to update the database goes here. --->
<cfoutput>
<h3>The e-mail address and phone number for user #Form.UserID#
have been added</h3>
</cfoutput>
</cfif>
<!--- The form. --->
<cfform action="#CGI.SCRIPT_NAME#">
User ID:<cfinput type="Text" name="UserID"><br>
Phone: <cfinput type="Text" name="phoneNo"><br>
E-mail: <cfinput type="Text" name="emailAddr"><br>
<cfinput type="submit" name="saveSubmit" value="Save Data"><br>
</cfform>
The expresserr.cfm page looks as follows:
<cfoutput>
You entered invalid data.<br>
Please click the browser Back button and try again<br>
#cferror.RootCause.detailMessage#
</cfoutput>
Using cftry and cfcatch tags
The self-posting form and action page looks as follows:
<!--- Use a Boolean variable to indicate whether all fields are good. --->
<cfset goodData="Yes">
<!--- Make sure the form was submitted. --->
<cfif isDefined("form.saveSubmit")>
<!--- The cftry block for testing the User ID value. --->
<cftry>
<!--- The cfparam tag checks the field data types. --->
<cfparam name="form.UserID" type="integer">
<!--- If the data is invalid, ColdFusion throws an expression exception. --->
<!--- Catch and handle the exception. --->
<cfcatch type="expression">
<!--- Set the data validity indicator to False. --->
<cfset goodData="No">
<cfoutput>
Invalid user ID.<br>
#cfcatch.detail#<br><br>
</cfoutput>
</cfcatch>
</cftry>
<!--- The cftry block for testing the e-mail address value. --->
<cftry>
<cfparam name="form.emailAddr" type="email">
Last updated 1/20/2012
764

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents