从表单中按顺序显示 CFLoop 项 [英] Display CFLoop Items in Order from Form

查看:18
本文介绍了从表单中按顺序显示 CFLoop 项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 form.html 页面上有以下表单,它提交给 cfpage.cfm.名字、姓氏、地址和年龄都会出现,但顺序不一致.有时它会显示姓氏、名字、地址和年龄.在另一种情况下,它可能会显示地址、名字、年龄,然后是姓氏.

I have the following form on the page form.html and it submits to cfpage.cfm. The first name, last name, address, and age all show up, but not in a consistent order. Sometimes it will show last name, first name, address, and age. In another instance it may show address, first name, age, and then last name.

我怎样才能显示 CFLoop 项目 - 以及用户在文本框中输入的文本 - 按照它们在表单中的显示顺序?我有多个通用表单,所以我必须在 cfpage.cfm 上使用一些通用代码来捕获馈送表单提交的任何内容.

How can I display the CFLoop items - with the text the user inputs in the text boxes - in the order they are shown in the form? I have multiple generic forms so I have to use a bit of generic code on cfpage.cfm to capture whatever the feeding form is submitting.

<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>

cfpage.cfm 上的代码

Code on cfpage.cfm

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

推荐答案

如果您希望它们以相同的顺序出现在表单上,​​那么您必须使用这种机制进行循环:

If you want them in the same order they appear on the form, then you must loop using this mechanism:

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

这是验证您所看到的问题的代码,并显示上述循环有效 - 另存为 stacktest.cfm:

Here is code that validates the problem you are seeing, and that shows the loop above works -- save as 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>

更新:第二个循环现在提供与第一个循环相同的输出,只是按顺序.根据提出问题的用户的要求更新.

Update: Second loop provides same output as first loop now, only in order. Updated by request of user who asked question.

这篇关于从表单中按顺序显示 CFLoop 项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆