formToNameValuePairs(formStruct[, doNotProcessList])
Last updated June 18, 2009
Version: 0 | Requires: CF7 | Library: StrLib
Description:
Pass me a form and I'll generate url-friendly concatenated name-value pairs of each form field. If you want me to ignore any of the form fields, I can do that too!
Return Values:
Returns a string
Example:
<cfoutput>#formToNameValuePairs(form, "SUBMIT,ISSUBMITTED")#</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
formStruct | form structure | Yes |
doNotProcessList | List of fields to ignore | No |
Full UDF Source:
<!---
I generate concatenated name-value pairs from forms.
@param formStruct form structure (Required)
@param doNotProcessList List of fields to ignore (Optional)
@return Returns a string
@author Stephen Withington (steve@stephenwithington.com)
@version 0, June 17, 2009
--->
<cffunction name="formToNameValuePairs" returntype="string" output="false" access="remote"
hint="pass me a form and i'll generate concatenated name-value pairs.">
<cfargument name="formStruct" type="struct" required="true" hint="the form struct to parse and concatenate" />
<cfargument name="doNotProcessList" type="string" required="false" hint="a list of form fields to ignore" default="" />
<cfset var local = structNew() />
<cfset local.nameValuePairs = "" />
<cfset local.doNotProcess = arguments.doNotProcessList />
<cfset local.field = "" />
<cfif structKeyExists(arguments,"formStruct") and structKeyExists(arguments.formStruct,"fieldnames")>
<cfloop list="#arguments.formStruct.fieldnames#" index="local.field">
<cfif not listFindNoCase(local.doNotProcess,local.field)>
<cfset local.doNotProcess = listAppend(local.doNotProcess,local.field) />
<cfset local.nameValuePairs = listAppend(local.nameValuePairs,lcase(local.field) & "=" & urlEncodedFormat(form[local.field], "utf-8"), "&") />
</cfif>
</cfloop>
</cfif>
<cfreturn local.nameValuePairs />
</cffunction>
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016