****A cf_boundform custom tag that does what I'm talking about:
<cfif thisTag.executionMode eq "start">
<!--- If submitted, process the form --->
<cfif isDefined("form.#attributes.name#") and form[attributes.name]>
<cfdump var="#form#">
<cfset formFields = listDeleteAt(form.fieldNames,
listFindNoCase(form.fieldNames, attributes.name))>
<cfif attributes.mode eq "update">
<cfupdate tablename="#attributes.tablename#"
datasource="#attributes.datasource#" formFields="#formFields#">
<cfelse>
<cfinsert tablename="#attributes.tablename#"
datasource="#attributes.datasource#" formFields="#formFields#">
</cfif>
<cflocation url=""> </cfif>
<!--- Else, render the form --->
<cfoutput>
<form name="#attributes.name#"
action="" method="post">
<input type="hidden" name="#attributes.name#" value="true">
<cfif attributes.mode eq "update">
<input type="hidden" name="#attributes.primaryKey#"
value="#attributes.primaryKeyValue#">
</cfif>
</cfoutput>
<cfelse>
</form>
</cfif>
***Now, a page that gets some records and lets you edit them or add a
new one, w/o having to write any sql (handled by cf_boundform)
<!--- Params --->
<cfparam name="url.userId" default="0">
<!--- Queries --->
<cfquery datasource="joeTest" name="getUsers">
SELECT TOP 10 * FROM testRecords
</cfquery>
<!--- Set up mode and form defaults --->
<cfif url.userId>
<cfset mode = "update">
<cfquery datasource="joeTest" name="getUser">
SELECT userId, username, emailAddress
FROM testRecords
WHERE userId = #url.userId#
</cfquery>
<cfelse>
<cfset mode = "insert">
<cfset getUser = structNew()>
<cfset getUser.userId = url.userId>
<cfset getUser.userName = "">
<cfset getUser.emailAddress = "">
</cfif>
<!--- Display user list --->
<cfoutput query="getUsers">
#getUsers.username# #getUsers.emailAddress# <a
href=""> </cfoutput>
<hr />
<cfif url.userId>
<h2>Update User</h2>
<cfelse>
<h2>Add New User</h2>
</cfif>
<!--- Form --->
<cf_boundForm name="editRow" action="" mode="#mode#"
tableName="testRecords" datasource="joeTest" primaryKey="userId"
primaryKeyValue="#getUser.userId#">
<cfoutput>
Username: <input name="username" type="text" value="#getUser.username#"><br>
E-Mail Address: <input name="emailAddress" type="text"
value="#getUser.emailAddress#"><br>
<input type="submit" value="Save Changes">
<cfif url.userId>
<input type="button" value="Cancel"
> </cfif>
</cfoutput>
</cf_boundForm>
-joe
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

