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.
view plain print about
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.
view plain print about
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.