[thelist] CF smoke and mirrors
Judah McAuley
judah at wiredotter.com
Thu Jul 19 13:11:49 CDT 2001
At 10:58 AM 7/19/2001 -0700, .jeff wrote:
>rory,
>
>:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>: From: Rory.Plaire at wahchang.com
>:
>: Currently I think that I will use a structure
>: and the function StructInsert to build a
>: collection of pages' form's fields... what do
>: you think?
>:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>you get the names from the database right now? just loop through that
>recordset and create form field variables.
>
><cfloop query="getfields">
> <cfparam name="form.#getfields.name#" default="">
></cfloop>
Alternatively, here is code I use to create forms from the db (pre-filled
with data):
<cfquery name="get_profile_columns" datasource="#application.datasource#"
dbtype="#application.dbtype#">
SELECT *
FROM member_profile
WHERE member_id = #session.member_id#
</cfquery>
<cfloop index="current_field" list="#get_profile_columns.columnlist#">
<cfset
SetVariable(current_field,Evaluate('get_profile_columns.'¤t_field))>
</cfloop>
You can also use CF_ColumnList (made by one of our own Evolters though, of
course, I forget which one at the moment). I use it in the following manner:
<cfquery name="get_profile_columns" datasource="#application.datasource#"
dbtype="#application.dbtype#">
SELECT *
FROM member_profile
WHERE 0 = 1
</cfquery>
<CF_ColumnList Query="#get_profile_columns#" ColumnList="profilecolList">
The CF_ColumnList returns the fields in the order they are in the database
(unlike Query.columnlist) and that allows you to build a form based off of
the database structure like so:
<cfloop index="iCol" list="#profilecolList#">
<tr>
<td>
#Replace(iCol,'_',' ','ALL')#
</td>
<td>
<cfif iCol EQ 'description' OR iCol EQ
'admin_comment'>
<textarea cols=30 rows=5 name="#iCol#"
wrap="soft"></textarea>
<cfelse>
<input type="text" name="#iCol#" size="30">
</cfif>
</td>
</tr>
</cfloop>
Hope this helps,
Judah
More information about the thelist
mailing list