Adobe COLDFUSION 9 Manual page 714

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Code
#FirstName#
#LastName#
#Salary#<br>
</cfoutput>
<br>
<cfoutput>Contractor: #Form.Contractor#
</cfoutput>
Testing for a variable's existence
Before relying on a variable's existence in an application page, you can test to see if it exists using the ColdFusion
function. A function is a named procedure that takes input and operates on it. For example, the
IsDefined
function determines whether a variable exists. CFML provides a large number of functions, which are documented in
the CFML Reference.
The following code prevents the error in the previous example by checking to see whether the Contractor Form
variable exists before using it:
<cfif IsDefined("Form.Contractor")>
<cfoutput>Contractor: #Form.Contractor#</cfoutput>
</cfif>
The argument passed to the
information on the
IsDefined
If you attempt to evaluate a variable that you did not define, ColdFusion cannot process the page and displays an error
message. To help diagnose such problems, turn on debugging in the ColdFusion Administrator. The Administrator
debugging information shows which variables are being passed to your application pages.
Requiring users to enter values in form fields
One of the limitations of HTML forms is the inability to define input fields as required. Because this is an important
requirement for database applications, ColdFusion lets you require users to enter data in fields. To specify a field as
required, you can do either of the following:
• Use the
attribute of the
required
• Use a hidden field that has a
technique with CFML and HTML form tags.
For example, to require that the user enter a value in the FirstName field of a
<cfinput type="Text" name="FirstName" size="20" maxlength="35" required="Yes">
To require that the user enters a value in the FirstName field of an HTML
<input type="Text" name="FirstName" size="20" maxlength="35">
<input type="hidden" name="FirstName_required">
In either of these examples, if the user leaves the FirstName field empty, ColdFusion rejects the form submittal and
returns a message informing the user that the field is required. You can customize the contents of this error message.
If you use a
attribute, you customize the message by using the
required
function must always be enclosed in double-quotation marks. For more
IsDefined
function, see the CFML Reference.
,
cfinput
cfselect
attribute composed of the field name and the suffix _
name
Last updated 8/5/2010
Description
Displays the value of the FirstName, LastName, and Salary fields for a
record, starting with the first record, then goes to the next line. Keeps
displaying the records that match the criteria you specified in the
SELECT statement, followed by a line break, until you run out of
records.
Closes the cfoutput block.
Displays a blank line followed by the text "Contractor": and the value
of the form Contractor check box.
A more complete example would test to ensure the existence of the
variable and would use the variable in the query.
,
, and
tags.
cftextarea
cftree
cfinput
tag, use the following syntax:
input
attribute, as follows:
message
IsDefined
. You can use this
required
tag, use the following syntax:
709

Advertisement

Table of Contents
loading

Table of Contents