Display CFLoop elements in order from form

I have the following form on form.html and it submits to cfpage.cfm. The first name, last name, address and age are displayed, but not in sequential order. Sometimes it will show the last name, first name, address and age. In another case, it can display the address, first name, age, and then last name.

How can I display CFLoop elements - with the text that the user types in the text fields in the order in which they appear on the form? I have several common forms, so I have to use some common code on cfpage.cfm to capture everything that the feed form submits.

<form id="theform" name="theform" action="cfpage.cfm" method="post">
First Name
<input type="text" name="first name">

Last Name
<input type="text" name="last name">

 Address
<input type="text" name="address">

Age
<input type="text" name="age">
</form>

Code on cfpage.cfm

<cfloop collection="#form#" item="theField">
<cfif theField is not "fieldNames">
#theField# = #form[theField]#<br>
</cfif>
</cfloop>
+4
source share
1 answer

, , , :

<cfloop index="i" list="#Form.FieldNames#" delimiters=",">
    #Form[i]#
</cfloop>

, , , , - stacktest.cfm:

<form id="theform" name="theform" action="stacktest.cfm" method="post">
First Name <input type="text" name="first name">
Last Name <input type="text" name="last name">
Address <input type="text" name="address">
Age <input type="text" name="age">
<input type="submit" value="submit"/>
</form>

<cfoutput>
<cfloop collection="#form#" item="theField">
<cfif theField is not "fieldNames">
    #theField# = #form[theField]#<br>
</cfif>
</cfloop>

<cfloop index="i" list="#Form.FieldNames#" delimiters=",">
    #i# = #Form[i]#<br>
</cfloop>
</cfoutput>

: , , . , .

+6

All Articles