Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 425

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Accessing and Using Data
<html>
<head> <title>Input form</title> </head>
<body>
<!--- If the Contractor check box is clear,
set the value of the Form.Contract to "No" --->
<cfif not isdefined("Form.Contract")>
<cfset Form.Contract = "N">
</cfif>
<!--- Insert the new record --->
<cfinsert datasource="cfdocexamples" tablename="EMPLOYEE">
<h1>Employee Added</h1>
<cfoutput> You have added #Form.FirstName# #Form.Lastname# to the employee database.
</cfoutput>
</body>
</html>
Save the page as insert_action.cfm.
2
View insert_form.cfm in your web browser and enter values.
3
Note: You might want to compare views of the Employee table in the cfdocexamples data source before and after
inserting values in the form.
Click Submit.
4
ColdFusion inserts your values into the Employee table and displays a confirmation message.
Reviewing the code
The following table describes the code and its function:
Code
<cfif not isdefined("Form.Contract")>
<cfset Form.Contract = "N">
</cfif>
<cfinsert datasource="cfdocexamples"
tablename="EMPLOYEE">
<cfoutput>You have added #Form.FirstName#
#Form.Lastname# to the employee
database.</cfoutput>
Note: If you use form variables in
sends to numeric, date, or time database columns. You can use the hidden field validation functions for these fields to
display a custom error message. For more information, see
page 703.
Creating an insert action page with cfquery
For more complex inserts from a form submittal, you can use a SQL INSERT statement in a
using a
tag. The SQL INSERT statement is more flexible because you can insert information selectively or
cfinsert
use functions within the statement.
Description
Sets the value of
box is unchecked, no value is passed to the action page; however, the database
field must have some value.
Creates a row in the Employee table of the cfdocexamples database. Inserts data
from the form into the database fields with the same names as the form fields.
Informs the user that values were inserted into the database.
or
tags, ColdFusion automatically validates any form data it
cfinsert
cfupdate
"Introduction to Retrieving and Formatting
Last updated 1/20/2012
Form.Contract
to
No
if it is not defined. If the Contractor check
420
Data" on
tag instead of
cfquery

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents