Solved

data Extraction from Form variables

Posted on 2011-09-19
13
321 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
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 …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

910 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

22 Experts available now in Live!

Get 1:1 Help Now