[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

data Extraction from Form variables

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
Gurpreet Singh Randhawa
Asked:
Gurpreet Singh Randhawa
  • 6
  • 5
  • 2
1 Solution
 
Brijesh ChauhanStaff IT EngineerCommented:
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
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
can u provide as asample or show me how to do this
0
 
Brijesh ChauhanStaff IT EngineerCommented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
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
 
Brijesh ChauhanStaff IT EngineerCommented:
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
 
Brijesh ChauhanStaff IT EngineerCommented:
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
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
btw, if there are other URL parameters passed, this technique is not going to work, also my ID can increase decrease also!

0
 
Brijesh ChauhanStaff IT EngineerCommented:
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
 
Brijesh ChauhanStaff IT EngineerCommented:
>> 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
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
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
 
devilJinKazamaCommented:
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
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
why duplicate(url) and yes i want to pass an array, how do i do that
0
 
devilJinKazamaCommented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now