Solved

data Extraction from Form variables

Posted on 2011-09-19
13
322 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 16

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 16

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
 
LVL 16

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 16

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 16

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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