我试图通过会话循环变量。在上一页中,我有一个下拉列表,允许用户选择1到5,它被设置为变量pcount。根据用户选择的内容,下一页上的表单会重复多次(pcount)。我需要能够通过会话循环变量,因此它知道“firstname_1”“firstname_2”等...然后在我的最后一个屏幕上显示为session#session.checkout.info.firstname_#Peoplecount#。我无法弄清楚如何在会话中正确编写变量。任何帮助将不胜感激。
<cfset Peoplecount = 1>
<cfloop
index="Add"
from="1"
to="#session.checkout.quantity.pcount#"
step="1"
>
<!---
If no checkout, send them to step 1
--->
<cfif not structKeyExists(session, "checkout")>
<cflocation url="enter.cfm" addToken="false">
</cfif>
<!--- initial defaults for the section --->
<cfif not structKeyExists(session.checkout, "info")>
<cfset session.checkout.info = {firstname_#Peoplecount#=""}>
</cfif>
<!--- form fields will default according to session values--->
<cfparam name="form.firstname_#Peoplecount#"
default="#session.checkout.info.firstname_#Peoplecount#">
<cfif structKeyExists(form, "submit")>
<cfset errors = []>
<cfif not arrayLen(errors)>
<cfset session.checkout.info =
{firstname_#Peoplecount#=form.firstname_#Peoplecount#}>
<cfset Peoplecount = PeopleCount + 1>
</cfloop>
<cflocation url="ownerCheck.cfm" addToken="false">
</cfif>
</cfif>
答案 0 :(得分:0)
<cfset session.checkout.info =
{firstname_#Peoplecount#=form.firstname_#Peoplecount#}>
应该更像是:
<cfset session.checkout.info = {
"firstname_#Peoplecount#" = form["firstname_#Peoplecount#"]
}>
<强>更新强>
在开始循环之前,首先创建session.checkout.info
作为空结构:
<cfset session.checkout.info = {}>
然后在IF语句中添加所需的键和值,例如
<cfset session.checkout.info["firstname_#Peoplecount#"] = form["firstname_#Peoplecount#"]>