Chapter 9: Handling Complex Data with Structures
117
Structure Example
Structures are particularly useful for grouping together a set of variables under a single
name. In the following example files, structures are used to collect information from a
form,
structinsert.cfm
, and to submit that information to a custom tag at
addemployee.cfm
.
These example files show how you can use a structure to pass information to a custom
tag, named CF_ADDEMPLOYEE.
Example file structinsert.cfm
<!--- This example shows how to use the StructInsert
function. It calls the CF_ADDEMPLOYEE custom tag,
which uses the addemployee.cfm file. --->
<HTML>
<HEAD>
<TITLE>Add New Employees</TITLE>
</HEAD>
<BODY>
<H1>Add New Employees</H1>
<!--- Establish parameters for first time through --->
<CFPARAM NAME="FORM.firstname" DEFAULT="">
<CFPARAM NAME="FORM.lastname" DEFAULT="">
<CFPARAM NAME="FORM.email" DEFAULT="">
<CFPARAM NAME="FORM.phone" DEFAULT="">
<CFPARAM NAME="FORM.department" DEFAULT="">
<!--- If all form fields are passed, create structure
named employee and add values --->
<CFIF #FORM.FIRSTNAME# EQ "">
<P>Please fill out the form.
<CFELSE>
<CFOUTPUT>
<CFSCRIPT>
employee=StructNew();
StructInsert(employee, "firstname", "#FORM.firstname#");
StructInsert(employee, "lastname", "#FORM.lastname#");
StructInsert(employee, "email", "#FORM.email#");
StructInsert(employee, "phone", "#FORM.phone#");
StructInsert(employee, "department", "#FORM.department#");
</CFSCRIPT>
<P>First name is #StructFind(employee, "firstname")#</P>
<P>Last name is #StructFind(employee, "lastname")#</P>
<P>EMail is #StructFind(employee, "email")#</P>
<P>Phone is #StructFind(employee, "phone")#</P>
<P>Department is #StructFind(employee, "department")#</P>
</CFOUTPUT>
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...