This is a standard problem, and it'd be nice to have good code to do
it. I'll volunteer mine as a starting point to get things rolling. The
following works, and I'm looking for ways to improve it. I seem to recall
Form fields became a Structure somewhere along the line. The following
works in CFAS 4.0.1
OH, in qry_SetWDDX.cfm I got stuck on Fusedocs, I'd appreciate any comments
on finishing that.
Finally, you'll notice I set Client variables in my own database, so, among
other things, I can avoid making CF parse a #-delimited string for every
client variable request.
best, paul
<!---
|| BEGIN FUSEDOC ||
|| PROPERTIES ||
Name: qry_SetWDDX.cfm
Author: [EMAIL PROTECTED]
|| RESPONSIBILITIES ||
I get arbitrary set of Form Fields sent to me. I store these in a database.
I put the field names and their values into a Structure.
I convert the Structure into a WDDX packet and store it in a database.
|| Attributes ||
--> form.fieldnames: a LIST
<++ [Form_Fields]: a WDDX CLIENT STRUCTURE
< Field_Name: a STRING
< Field_Value: a STRING, INTEGER, or NUMBER
<++ aWDDXpacket: a STRING
-->
|| END FUSEDOC ||
--->
<!--- Put data in "Form.Field_Name" format into Structure --->
<CFSET STTEMP = STRUCTNEW()> <!--- temporary structure --->
<CFSET FORM_FIELDS = STRUCTNEW()> <!--- final structure for Form values --->
<CFLOOP INDEX="FieldName" LIST="#form.fieldnames#">
<CFSET STTEMP["Field_Name"] = "#FieldName#">
<CFSET STTEMP["Field_Value"] = "#Evaluate(FieldName)#">
<CFSET FORM_FIELDS[STTEMP["Field_Name"]] = STRUCTCOPY(STTEMP)>
<CFSET TMPVAR = STRUCTCLEAR(STTEMP)>
</CFLOOP>
<!--- Put structure into WDDX packet --->
<CFWDDX ACTION="CFML2WDDX" INPUT="#form_fields#" OUTPUT="aWDDXpacket">
<!--- Put WDDXed data into DB --->
<CFQUERY DATASOURCE="#REQUEST.CLIENT_DSN#" USERNAME="#REQUEST.CLIENT_USER#"
PASSWORD="#REQUEST.CLIENT_PASS#">
UPDATE ClientData
SET Form_Fields = '#aWDDXpacket#',
Form_Fields_List = '#Form.Fieldnames#'
WHERE CFI = #VAL(URL.CFI)#
AND CFT = #VAL(URL.CFT)#
</CFQUERY>
An the other direction is:
<!---
|| BEGIN FUSEDOC ||
|| PROPERTIES ||
Name: qry_GetWDDX.cfm
Author: [EMAIL PROTECTED]
|| RESPONSIBILITIES ||
I get a WDDX packet and a list of Form Field Names from a database.
I use the WDDX packet and Field Names to put the WDDX packet data
into the "Form.FormFieldName" format
|| END FUSEDOC ||
--->
<!--- Get current WDDX packet from DB --->
<CFQUERY NAME="GetForm_Fields" DATASOURCE="#REQUEST.CLIENT_DSN#"
USERNAME="#REQUEST.CLIENT_USER#" PASSWORD="#REQUEST.CLIENT_PASS#">
SELECT Form_Fields,Form_Fields_List
FROM ClientData
WHERE CFI = #VAL(URL.CFI)#
AND CFT = #VAL(URL.CFT)#
</CFQUERY>
<!--- Get WDDX data --->
<CFSET FORM_FIELDS = STRUCTNEW()>
<CFWDDX ACTION="WDDX2CFML" INPUT="#GetForm_Fields.Form_Fields#"
OUTPUT="FORM_FIELDS">
<!--- Convert data in Structure to "Form.Variable_Name" format --->
<CFLOOP INDEX="FieldName" LIST="#GetForm_Fields.Form_Fields_List#">
<CFSET "Form.#FieldName#" = "#Form_Fields["#FieldName#"]["Field_Value"]#">
</CFLOOP>
At 07:43 AM 1/16/01 -0900, you wrote:
>In my app flow, I rely upon populating structures from client-var WDDX
>packets, and then from structures back into WDDX. The form field defaults as
>structure values thing works great with this
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists