MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 124

Developing coldfusion mx applications
Table of Contents

Advertisement

Code
<cf_addemployee
empinfo="#duplicate(employee)#">
</cfif>
<form action="newemployee.cfm" method="Post">
First Name:&nbsp;
<input name="firstname" type="text"
hspace="30"
maxlength="30"><br>
Last Name:&nbsp;
<input name="lastname" type="text" hspace="30"
maxlength="30"><br>
EMail:&nbsp;
<input name="email" type="text" hspace="30"
maxlength="30"><br>
Phone:&nbsp;
<input name="phone" type="text" hspace="20"
maxlength="20"><br>
<p>Department:&nbsp;
<input name="department" type="text"
hspace="30"
maxlength="30"><br>
<br>
<input type="Submit" value="OK">
</form>
Example file addemployee.cfm
The following file is an example of a custom tag used to add employees. Employee information is
passed through the employee structure (the empinfo attribute). For databases that do not support
automatic key generation, you must also add the Emp_ID.
<cfif StructIsEmpty(attributes.empinfo)>
<cfoutput>
Error. No employee data was passed.<br>
</cfoutput>
<cfexit method="ExitTag">
<cfelse>
<!--- Add the employee --->
<cfquery name="AddEmployee" datasource="cfsnippets">
INSERT INTO Employees
(FirstName, LastName, Email, Phone, Department)
VALUES (
'#attributes.empinfo.firstname#' ,
'#attributes.empinfo.lastname#' ,
'#attributes.empinfo.email#' ,
'#attributes.empinfo.phone#' ,
'#attributes.empinfo.department#' )
</cfquery>
</cfif>
<cfoutput>
<hr>Employee Add Complete
</cfoutput>
124
Chapter 5: Using Arrays and Structures
Description
Call the
cf_addemployee
a copy of the employee structure in the
empinfo attribute.
The duplicate function ensures that the custom
tag gets a copy of the employee structure, not
the original. While this is not necessary in this
example, it is good practice because it
prevents the custom tag from modifying the
calling page's structure contents.
The data form. When the user clicks Submit,
the form posts the data to this ColdFusion
page.
custom tag and pass it

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Questions and answers

This manual is also suitable for:

Coldfusion mx

Table of Contents