Created
October 11, 2010 14:22
-
-
Save artlung/620581 to your computer and use it in GitHub Desktop.
StructToQueryString() ColdFusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
<cfset submit_URL = StructNew()> | |
<cfset submit_URL.something = 1> | |
<cfset submit_URL.something2 = 2> | |
<cfset submit_URL.other = "hello world"> | |
<cfoutput> | |
#StructToQueryString(Submit_URL)# | |
</cfoutput> | |
Should output this: | |
?other=hello%20world&something2=2&something=1&CFID=426&CFTOKEN=105727A3-8DBA-ACA9-846314DB41BACE53 | |
---> | |
<cffunction name="StructToQueryString" returnType="string" > | |
<cfargument name="structure" type="struct" required="yes"> | |
<cfset UrlArray = ArrayNew(1)> | |
<cfloop collection=arguments.structure item="key"> | |
<cfscript> | |
value = StructFind(arguments.structure, key); | |
ArrayAppend(UrlArray, "#URLEncodedFormat(key)#=#URLEncodedFormat(value)#"); | |
</cfscript> | |
</cfloop> | |
<cfif IsDefined("URLTOKEN")> | |
<cfscript> | |
ArrayAppend(UrlArray, URLTOKEN); | |
</cfscript> | |
</cfif> | |
<cfreturn "?" & ArrayToList(UrlArray, '&')> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment