Solved

data Extraction from Form variables

Posted on 2011-09-19
13
323 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
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.

 
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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cfchart display 12 104
On Submit return to same spot 7 95
How can I use EncodeForURL() in ColdFusion with CFGRID 5 56
REReplaceNoCase help 1 43
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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