Structure Example - MACROMEDIA COLDFUSION 4.5-DEVELOPING WEB Develop Manual

Developing web applications with coldfusion
Table of Contents

Advertisement

Chapter 9: Handling Complex Data with Structures

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
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>
, and to submit that information to a custom tag at
.
117

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION 4.5-DEVELOPING WEB and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Coldfusion 4.5

Table of Contents