如何访问 this.sameFormFieldsAsArray 值
How to Access this.sameFormFieldsAsArray values
在我的 Application.cfc 文件中,我设置了 this.sameFormFieldsAsArray = True
。
当我转储表单时,我看到了数组中的值。如果我想遍历它们并执行其他操作,现在如何访问它们?
更新:我正在尝试匹配正在传递的两个表单字段的值。如果form.sched
包含form.bldgarea
,输出两者的值。它错误地指出它在位置 4 找不到任何东西。知道我做错了什么吗?
<cfloop index="i" from="1" to="#arrayLen(form.bldgarea)#">
<cfloop index="i" from="1" to="#arrayLen(form.sched)#">
<cfif #form.sched[i]# contains #form.bldgarea[i]#>
<cfoutput>
#form.sched[i]#, #form.bldgarea[i]#
</cfoutput>
</cfif>
</cfloop>
</cfloop>
更新:
如果您在提交时遇到错误,我怀疑您 运行 进入了添加到 CF9+ 的安全功能 Limits the maximum number of POST fields allowed。一个简单的选择是增加 CF 管理员中的限制。
另一种可能性是重组表格。将 select 列表移到单独的 <form>
中,这样它们就不会被提交。当用户单击主窗体中的提交按钮时,使用 jQuery 构建 selected 项的列表并将其存储在隐藏字段中。类似于 this thread 中的方法。然后在操作页面上,遍历收到的值列表。
总结评论中的讨论:
The ultimate goal is to extract the selected sched
value only when
the associated bldgarea
box is checked.
我建议采用稍微不同的方法。假设您有某种(唯一的)数字 ID 来表示每个建筑物,将其用作复选框 "value",而不是建筑物名称。
<input type="checkbox" name="bldgarea" value="#queryName.buildingID#">
然后使用建筑物 ID 值为每个 select 列表生成唯一的名称:
<select name="sched_#queryName.buildingID#">
提交表单后,form.bldgarea
将仅包含 selected 建筑物的 ID。循环遍历该数组并使用关联数组表示法动态获取关联的 sched
值。
<cfloop array="#form.bldgarea#" index="variables.buildingID">
<cfoutput>
buildingID = #variables.buildingID#
schedID = #FORM["sched_"& variables.buildingID]#
<br>
</cfoutput>
</cfloop>
注意: 只有勾选了某些内容才会提交复选框。使用前请务必验证 form.bldgarea
是否存在。
在我的 Application.cfc 文件中,我设置了 this.sameFormFieldsAsArray = True
。
当我转储表单时,我看到了数组中的值。如果我想遍历它们并执行其他操作,现在如何访问它们?
更新:我正在尝试匹配正在传递的两个表单字段的值。如果form.sched
包含form.bldgarea
,输出两者的值。它错误地指出它在位置 4 找不到任何东西。知道我做错了什么吗?
<cfloop index="i" from="1" to="#arrayLen(form.bldgarea)#">
<cfloop index="i" from="1" to="#arrayLen(form.sched)#">
<cfif #form.sched[i]# contains #form.bldgarea[i]#>
<cfoutput>
#form.sched[i]#, #form.bldgarea[i]#
</cfoutput>
</cfif>
</cfloop>
</cfloop>
更新:
如果您在提交时遇到错误,我怀疑您 运行 进入了添加到 CF9+ 的安全功能 Limits the maximum number of POST fields allowed。一个简单的选择是增加 CF 管理员中的限制。
另一种可能性是重组表格。将 select 列表移到单独的 <form>
中,这样它们就不会被提交。当用户单击主窗体中的提交按钮时,使用 jQuery 构建 selected 项的列表并将其存储在隐藏字段中。类似于 this thread 中的方法。然后在操作页面上,遍历收到的值列表。
总结评论中的讨论:
The ultimate goal is to extract the selected
sched
value only when the associatedbldgarea
box is checked.
我建议采用稍微不同的方法。假设您有某种(唯一的)数字 ID 来表示每个建筑物,将其用作复选框 "value",而不是建筑物名称。
<input type="checkbox" name="bldgarea" value="#queryName.buildingID#">
然后使用建筑物 ID 值为每个 select 列表生成唯一的名称:
<select name="sched_#queryName.buildingID#">
提交表单后,form.bldgarea
将仅包含 selected 建筑物的 ID。循环遍历该数组并使用关联数组表示法动态获取关联的 sched
值。
<cfloop array="#form.bldgarea#" index="variables.buildingID">
<cfoutput>
buildingID = #variables.buildingID#
schedID = #FORM["sched_"& variables.buildingID]#
<br>
</cfoutput>
</cfloop>
注意: 只有勾选了某些内容才会提交复选框。使用前请务必验证 form.bldgarea
是否存在。