Solved

Parse brackets in the URL string

Posted on 2011-02-28
8
579 Views
Last Modified: 2012-05-11
Hi,

I was trying to figure out how to parse brackets in the URL string. I have a javascript program that serializes my data and passes the following URL string to my coldfusion page

http://hsecfs1/developmentdmz/mctr/sortAjax.cfm?item[]=1&item[]=2&item[]=3

Unfortunatley, I can't figure out how to pull the data.

<cfoutput>#url.item[]#</cfoutput> doesn't seem to work. Any advice would be appreciated. Thank you!
0
Comment
Question by:jsimonuchc
  • 3
  • 3
  • 2
8 Comments
 
LVL 3

Assisted Solution

by:dagaz_de
dagaz_de earned 100 total points
ID: 34998797
can you leave the brackets away, i think it wont work with brackets. Without you will get a comma separated list. Then you can loop over the list to get the values....

?item=1&item=2&item=3

then
<cfoutput>#url.item#</cfoutput>

<cfloop list="#url.item#" index="i">

     <!--- Do something with i --->
    <cfoutput>#i#</cfoutput>
<cfloop>
0
 
LVL 3

Expert Comment

by:dagaz_de
ID: 34998808
Sorry the cfloop was not closed correct:

<cfoutput>#url.item#</cfoutput>

<cfloop list="#url.item#" index="i">

     <!--- Do something with i --->
    <cfoutput>#i#</cfoutput>
</cfloop>
0
 
LVL 1

Author Comment

by:jsimonuchc
ID: 34998830
No, I cannot remove the brackets (or I haven't figured out how to do it yet).
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 400 total points
ID: 34998843
wow, that's unique.

How about  <cfset theValue = url["item[]"]>

You could also dump the url to see what's in there

<cfdump var="#url#">


The result, if you can read it, is a comma delimited list of values in one variable:  1,2,3  because the same name is used in each.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:jsimonuchc
ID: 34998861
CFDUMP shows me a struct with the following contents:

ITEM[]       1,2,3
0
 
LVL 1

Author Comment

by:jsimonuchc
ID: 34998869
Awesome,  <cfset theValue = url["item[]"]> seems to work.
It gives me the values in a comma separated list.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 34998885

perfect, glad it works
0
 
LVL 3

Expert Comment

by:dagaz_de
ID: 34998988
now you can loop over the list like i told you....

<cfset theValue = url["item[]"]>

<cfloop list="#theValue#" index="i">

     <!--- Do something with i --->
    <cfoutput>#i#</cfoutput>
</cfloop>
      
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now