Normally when there one,two even three values in the URL It is very easy to just set up a new structure manually to hold those values like so.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfset data = StructNew()>
<cfset data.one = url.one>
<cfset data.two = url.two>
<cfset data.three = url.three>
1<cfset data = StructNew()>
2<cfset data.one = url.one>
3<cfset data.two = url.two>
4<cfset data.three = url.three>
If you have more values though you may want to do this dynamically. This was the case last night as I was updating a certain IPN (that will go unnamed) that decided to change their form post to a url post, thanks for the notice guys! In my example I well over 50 values being passed back in the url so there is no way I am going to set these up manually. This is a fairly simple procedure but I thought I would share it anyways.
- The first thing you need to do is grab all of the query string values, this can be accessed from the CGI scope.
- Then we will create a local structure to hold all of our data in my case I just named it data
- Finally we are going to loop our query string using a ampersand as the delimiter. This will give us our key/pair value as the index so to set our structure up we just tell our structure that our key is the first part of the list (using = as delimiter) and the value is the last part of the list.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<!--- query string --->
<cfset str = CGI.QUERY_STRING>
<!--- local structure --->
<cfset data = StructNew()>
<!--- loop our query string values and set them in our structure --->
<cfloop list="#str#" index="key" delimiters="&">
<cfset data["#listFirst(key,'=')#"] = urlDecode(listLast(key,"="))>
</cfloop>
<cfdump var="#data#">
1<!--- query string --->
2<cfset str = CGI.QUERY_STRING>
3<!--- local structure --->
4<cfset data = StructNew()>
5<!--- loop our query string values and set them in our structure --->
6<cfloop list="#str#" index="key" delimiters="&">
7 <cfset data["#listFirst(key,'=')#"] = urlDecode(listLast(key,"="))>
8</cfloop>
9
10
11<cfdump var="#data#">
Another easy but useful example.
This entry was posted on September 7, 2007 at 3:46 PM and has received 4167 views. Comments 11 |
Print this entry.
#1 by Raymond Camden on 9/7/07 - 3:07 PM
<cfset data = duplicate(url)>
?
#2 by Todd Rafferty on 9/7/07 - 3:11 PM
#3 by Dan on 9/7/07 - 3:14 PM
#4 by Todd Rafferty on 9/7/07 - 3:19 PM
#5 by Dan on 9/7/07 - 3:23 PM
#6 by Todd Rafferty on 9/7/07 - 3:33 PM
#7 by Dan Vega on 9/7/07 - 3:38 PM
#8 by Dan on 9/7/07 - 3:41 PM
#9 by Josen Ruiseco on 9/7/07 - 7:47 PM
Josen
#10 by Eric Hynds on 8/6/08 - 9:58 AM
#11 by Nathan Blixt on 10/18/12 - 2:07 AM