• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Form Structure Sorting

Participant ,
Oct 12, 2006 Oct 12, 2006

Copy link to clipboard

Copied

How can I sort the form structure on output? Here is my script.
<table>
<tr>
<th>Variable Name</th>
<th>Value</th>
</tr>
<!--- loop over the Form structure and output all
of the variable names and their associated
values --->
<cfloop collection="#Form#" item="VarName">
<cfoutput>
<tr>
<td>#VarName#</td>
<td>#Form[VarName]#</td>
</tr>
</cfoutput>
</cfloop>
TOPICS
Advanced techniques

Views

733

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 12, 2006 Oct 12, 2006

Copy link to clipboard

Copied

You would sort the output by the query....

<cfquery name="myquery" datasourse="application.ds">
Select ID, whatever, fields, you, need
From tblMytable
Order by Mysortingcrit
</cfquery>


<cfloop query="myquery">

<---this is where you would put your table structure and variables--->

</cfloop>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 12, 2006 Oct 12, 2006

Copy link to clipboard

Copied

he's not sorting a query. he's sorting a form structure.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 12, 2006 Oct 12, 2006

Copy link to clipboard

Copied

I was thinking that maybe, I can dump the form elements into a query and then sort them that way and just out put from the query. I am little stuck on the code for this. Any help would be appreciated.

<cfset form.harry = "hello">
<cfset form.fred = "goodbye">

<cfloop collection="#Form#" item="VarName">
<cfset count = 1>
<cfset myQuery = QueryNew("#VarName#,")>
<cfset temp = QuerySetCell(myQuery, "#VarName#", "#Form[VarName]#", #Count#)>
<cfset count = count + 1>
</cfloop>
<cfdump var="#myQuery#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 12, 2006 Oct 12, 2006

Copy link to clipboard

Copied

<cfoutput>
<cfloop list="#listSort(struckKeyList(form))# index="key">
form.#key# = #form[key]#<br>
</cfloop>
</cfoutput>

Correct whatever syntax errors I made typing that and you should have
what you want. As long as you just want ascending or descending
alphabetical order.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 12, 2006 Oct 12, 2006

Copy link to clipboard

Copied

Ian, I tried to get your code to work. I modified it to look like this.
<cfloop list="#listSort(struckKeyList(form,","), "ASC")#" index="i">
<cfoutput>
form.#i# = #form #<br>
</cfoutput>
</cfloop>
However, I get this error message.
Variable STRUCKKEYLIST is undefined.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 12, 2006 Oct 12, 2006

Copy link to clipboard

Copied

As I said debug my typing StructKeyList() NOT StruckKeyList()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 12, 2006 Oct 12, 2006

Copy link to clipboard

Copied

Ian, this is what I got with your code.
Parameter validation error for function LISTSORT.
The function takes 2 to 4 parameters.

This is what I am running from your code.
<cfset form.harry = "hello">
<cfset form.fred = "goodbye">

<cfoutput>
<cfloop list="#listSort(struckKeyList(form))#" index="key">
form.#key# = #form[key]#<br>
</cfloop>
</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 12, 2006 Oct 12, 2006

Copy link to clipboard

Copied

LATEST
Code tested and ran.

<cfoutput>
<cfloop list="#listSort(structKeyList(form),'textNoCase')#" index="key">
form.#key# = #form[key]#<br/>
</cfloop>
</cfoutput>


My previous examples where just to give you the idea of what functions
and logic you could use. I don't use these functions everyday so I do
not know all required parameters without looking at the documentation.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation