– Common Function Library Project

formToNameValuePairs(formStruct[, doNotProcessList])

Last updated June 17, 2009


Stephen Withington

Version: 0 | Requires: CF7 | Library: StrLib

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


<cfoutput>#formToNameValuePairs(form, "SUBMIT,ISSUBMITTED")#</cfoutput>


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 ( 
 @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"), "&") />                        

	<cfreturn local.nameValuePairs />    
blog comments powered by Disqus


Latest Additions

Kevin Cotton added
May 5, 2016

Raymond Camden added
April 25, 2016

Chris Wigginton added
January 18, 2016

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson