Skip to content

Instantly share code, notes, and snippets.

@boughtonp
Created March 22, 2014 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boughtonp/9705827 to your computer and use it in GitHub Desktop.
Save boughtonp/9705827 to your computer and use it in GitHub Desktop.
StructToQueryString
<cffunction name="StructToQueryString" returntype="String" output=false access="public"
hint="Converts a struct into a url-encoded querystring."
>
<cfargument name="Data" type="Struct" required=true />
<cfset var QS = '' />
<cfif NOT StructCount(Arguments.Data)><cfreturn '' /></cfif>
<cfloop item="local.Key" collection=#Arguments.Data#>
<cfif NOT StructKeyExists(Arguments.Data,Key) ><cfcontinue /></cfif>
<cfset QS &= '&' & encodeForUrl(Key) & '=' & encodeForUrl(Arguments.Data[Key]) />
</cfloop>
<cfreturn QS.substring(1) />
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment