8 Replies Latest reply on Oct 12, 2006 3:05 PM by Newsgroup_User

    Form Structure Sorting

    murpg
      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>
        • 1. Re: Form Structure Sorting
          shastamatt
          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>
          • 2. Re: Form Structure Sorting
            chrisbrickhouse
            he's not sorting a query. he's sorting a form structure.
            • 3. Re: Form Structure Sorting
              murpg Level 1
              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#">
              • 4. Re: Form Structure Sorting
                Level 7
                <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.
                • 5. Re: Form Structure Sorting
                  murpg Level 1
                  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.
                  • 6. Re: Form Structure Sorting
                    Level 7
                    As I said debug my typing StructKeyList() NOT StruckKeyList()
                    • 7. Re: Form Structure Sorting
                      murpg Level 1
                      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>
                      • 8. Re: Form Structure Sorting
                        Level 7
                        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.