Copy link to clipboard
Copied
I am working on a project where there is a list of items from the database and the screen is populated with the items, description, and a checkbox for the user to select. When the user processes the screen only those items are stored in the database. I have it all working but no real good idea on how to save the selected items to the database. Need some assistance on this one.
<!--- This sould be the MS SQL --->
<cfif isDefined('form.test')>
<cfoutput>This is a list of the items selected</cfoutput>
<cfloop list="#form.test#" index="i">
<cfparam name="form.#i#" default="">
#i#: #FORM#
<br>
</cfloop>
</cfif>
<!--- Get the Data from the MS SQL Database --->
<cfquery name="getData">
Select
PositionID,
PositionLevelID,
Title,
ListSortOrder
From Position
Where PositionLevelID = 2
Order By ListSortOrder
</cfquery>
<!--- Start the screen --->
<!DOCTYPE html>
<html>
<head>
<title>
Equipment Listing
</title>
<link rel="stylesheet" type="text/css" href="../styles.css"/>
</head>
<body>
<cfform name="testing">
<cfloop query="GetData">
<input type="checkbox" name="#GetData.Title#" value="#GetData.PositionID#"/>
<cfoutput>
#title# #PositionID#
<br>
</cfoutput>
</cfloop>
<input name="test" type="Submit" value="testing">
</cfform>
</body>
</html>
Copy link to clipboard
Copied
Put "action" attribute in the cfform which assigns where you want to submit the form. Then in the action page, you use cfquery to insert the selected items to database.
Get Ben Forta's ColdFusion book. It's all there. Or, go to easycfm.com or learncfinaweek.com. There are tons of examples!