Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 107

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
<!--- Create a structure and set its contents. --->
<cfset departments=structnew()>
<cfset val=StructInsert(departments, "John", "Sales")>
<cfset val=StructInsert(departments, "Tom", "Finance")>
<cfset val=StructInsert(departments, "Mike", "Education")>
<!--- Build a table to display the contents --->
<cfoutput>
<table cellpadding="2" cellspacing="2">
<tr>
<td><b>Employee</b></td>
<td><b>Department</b></td>
</tr>
<!--- Use cfloop to loop through the departments structure.
The item attribute specifies a name for the structure key. --->
<cfloop collection=#departments# item="person">
<tr>
<td>#person#</td>
<td>#Departments[person]#</td>
</tr>
</cfloop>
</table>
</cfoutput>
Structure examples
Structures are useful for grouping a set of variables under a single name. The following example uses structures to
collect information from a form, and to submit that information to a custom tag, named
information on creating and using custom tags, see
Example file newemployee.cfm
The following ColdFusion page shows how to create structures and use them to add data to a database. It calls the
custom tag, which is defined in the addemployee.cfm file.
cf_addemployee
<html>
<head>
<title>Add New Employees</title>
</head>
<body>
<h1>Add New Employees</h1>
<!--- Action page code for the form at the bottom of this page. --->
<!--- 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 at least the firstname form field is passed, create
a structure named employee and add values. --->
<cfif #Form.firstname# eq "">
<p>Please fill out the form.</p>
"Creating and Using Custom CFML
Last updated 1/20/2012
. For
cf_addemployee
Tags" on page 208.
102

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents