Solved

data Extraction from Form variables

Posted on 2011-09-19
13
318 Views
Last Modified: 2012-05-12
I just dumped my Form and i am getting my Form data as follows

DATA ID=1&ID=2&ID=3&ID=4&ID=4&ID=5&ID=6&ID=7&opt=1  
FIELDNAMES DATA  

This is coming in form Dump. I want to use the Form Struct in the Query, how can i convert it instruct so i can use it in my CFC or any other way, Guide
0
Comment
  • 6
  • 5
  • 2
13 Comments
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 36559568
you can consider ID=1&ID=2&ID=3&ID=4&ID=4&ID=5&ID=6&ID=7&opt=1 as a LIST separated by '&'.. convert to a struct and pass to your CFC
0
 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 36559616
can u provide as asample or show me how to do this
0
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 36559625
What is that you want to extract from above code ??.. below is one way you can do it ..


<cfset lstID = 'ID=1&ID=2&ID=3&ID=4&ID=4&ID=5&ID=6&ID=7&opt=1' />
<cfset objStr = StructNew() />
<cfset ID = 0 />
 
<!--- Loop over the list to add mappings to the struct. --->
<cfloop index="strID" list="#lstID#" delimiters="&">
<cfset ID = ID + 1 />
 
	<cfset objStr[ ID ] = "#strID#" />
 
</cfloop>

<cfdump var="#objStr#">

Open in new window

0
 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 36559679
Thanks btw i also want to remove

ID=

also will it not hamper performance if there are more than 2000 records, is there a way to do as an array
0
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 36559709
ARRAY - just do

<cfdump var="#ListToArray(lstID,'&')#">

Just take the RIGHT most value from ID =1 ..

I don't think it is SO complex that 2000 records will affect it.. but you can try and see the performance..

<cfset lstID = 'ID=1&ID=2&ID=3&ID=4&ID=4&ID=5&ID=6&ID=7&opt=1' />
<cfset objStr = StructNew() />
<cfset ID = 0 />
 
<!--- Loop over the list to add mappings to the struct. --->
<cfloop index="strID" list="#lstID#" delimiters="&">
<cfset ID = ID + 1 />
 
	<cfset objStr[ ID ] = "#Right(strID,1)#" />
 
</cfloop>

<cfdump var="#objStr#">

Open in new window

0
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 36559731
This will give you ID = PART ..

<cfset lstID = 'ID=1&ID=2&ID=3&ID=4&ID=4&ID=5&ID=6&ID=7&opt=1' />
<cfset arryID = ListToArray(lstID,'&') />

<cfloop array="#arryID#" index="ID">
	<cfoutput>ID = #right(ID,1)# </cfoutput>
</cfloop>

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 36559842
btw, if there are other URL parameters passed, this technique is not going to work, also my ID can increase decrease also!

0
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 36559906
Explain more on what exactly you are looking for, it would not really matter if the ID increase or Decrease, you can always have it converted to array or structure and do your calculations, can you share your CFC on how you are passing it in there ???
0
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 36559936
>> if there are other URL parameters passed

You can just put one more condition in there to work.. just check if your array index cotains ID or NOT... that way if you pass any other parameters will not be considered..
<cfset lstID = 'ID=1&ID=2&ID=3&ID=4&ID=4&ID=5&ID=6&ID=7&opt=1' />
<cfset arryID = ListToArray(lstID,'&') />

<cfloop array="#arryID#" index="IdIndex">
	<cfif IdIndex contains 'ID'>
		<cfoutput> ID = #right(IdIndex,1)# </cfoutput>
    </cfif>
</cfloop>

Open in new window

0
 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 36559979
well i just tell you the scenario!

I am getting the values from the javascript passed as hidden fields like this

See me this Questionhttp://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27309846.html

inside this i am also the Input type hidden with having same name and the value is different everytime, u will see!

so i need the ID's passed are sent to the div. there the id and the option is select is send through post to the ajax request and i need the ID's and the option id to move to the cfc and get the results

0
 
LVL 3

Expert Comment

by:devilJinKazama
ID: 36570434
the URL scope is a struct, deosnt matter what you have in there you can easily put them in a structure and pass it into your CFC

<cfloop list="#structKeyList(url)#" index="i">
     <cfset setVariable("myStruct[#i#]",evaluate('url.' & i))>
</cfloop>

<cfdump var="#myStruct#">

So you can pass in the structure or in the loop set it in an array, query or list and then pass it in.

if you want to pass it in as a struct just pass in #duplicate(url)#
0
 
LVL 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 36571736
why duplicate(url) and yes i want to pass an array, how do i do that
0
 
LVL 3

Accepted Solution

by:
devilJinKazama earned 500 total points
ID: 36571829
just good practice to use duplicate so u dont end up changing the original scope variables.

to insert all your url variables in an array simply insert into an array inside the loop

<cfset myArray = arrayNew(1)>

<cfloop list="#structKeyList(url)#" index="i">
     <cfset arrayAppend(myArray,evaluate('url.' & i))>
</cfloop>

<cfdump var="#myArray#">

you can pass that into your function. but dont you need it in a name value format? how would you know which is ID and which is the opt variable?

to be honest i still dont know why you end up with a list like that. if you are trying to process a bunch of IDs you displayed on the form page then its way easier if have the IDs in a hidden form field so you end up with a nice list on your process page,

form page :
<input type+"hidden" value"#ID#" name="IDList"/>

process page :
form.IDList would equal your IDs in a list format (1,2,3,4,etc)

to convert it to an array you would just use #listToArray(form.IDList)# and you pass that into the function
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

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

13 Experts available now in Live!

Get 1:1 Help Now