CFLib.org – Common Function Library Project

formToNameValuePairs(formStruct[, doNotProcessList])

Last updated June 17, 2009

author

Stephen Withington

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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson