访问动态形式的变量 [英] Accessing variables of a dynamic form
问题描述
我使用 cfloop
创建一个表单,并且在提交表单时需要单独访问每个变量。我需要在循环中使用表单的选定条目,将我的选择添加到数据库。
这是我的表单:
< form method = post>
< input type =hiddenname =isPostvalue =1>
...
< cfoutput>
< cfloop query =client_admin_surveys>
< input type =textsize =35name =surveyIDid =surveyIDvalue =#id#>
< input type =textsize =35name =surveyNameid =surveyNamevalue =#name#>
< input type =checkboxname =amplifyid =amplify>
< input type =checkboxname =enchanceid =enchance>
< input type =checkboxname =pacifyid =pacify>
< input type =checkboxname =pacifyUrgentid =pacifyUrgent>
< / cfloop>
< / cfoutput>
...
< input type =submitname =submitvalue =Submit>
< / form>
发布表单后,结果会分组我的所有选择,因为我有相同的名称我的表单元素。我尝试在每个名称旁边添加一个 i
计数,使其不同,但是我对如何处理这些字段有点困惑。
pre>
< input type =checkboxname =amplify#client_admin_surveys.currentRow#id =amplify>
会工作。
喜欢在处理页面上为计数器添加表单字段
< input type =hiddenname = countervalue =#client_admin_surveys.recordCount#/>
然后在处理页面上,您可以循环计数器并使用括号符号访问表单字段
< cfloop from =1to =#form.counter#indexd =i>
< cfset thisAmplify = form [amplify& i] />
< cfset thisEnhance = form [enhance& i] />
<!---- more logic here --->
< / cfloop>
I am creating a form with cfloop
and need to access each variable individually when submitting the form. I need to use the selected entries of the form in a loop that will add my selections to a database.
This is my form:
<form method="post">
<input type="hidden" name="isPost" value="1">
...
<cfoutput>
<cfloop query="client_admin_surveys">
<input type="text" size="35" name="surveyID" id="surveyID" value="#id#">
<input type="text" size="35" name="surveyName" id="surveyName" value="#name#">
<input type="checkbox" name="amplify" id="amplify">
<input type="checkbox" name="enchance" id="enchance">
<input type="checkbox" name="pacify" id="pacify">
<input type="checkbox" name="pacifyUrgent" id="pacifyUrgent">
</cfloop>
</cfoutput>
...
<input type="submit" name="submit" value="Submit">
</form>
After posting the form, the results group all of my selections because I have the same "name" for my form elements. I tried adding an i
count next to each name to make it different but then I got a bit confused about how to process the fields.
You started down the correct path when you added the counter - go back and add that, something like:
<input type="checkbox" name="amplify#client_admin_surveys.currentRow#" id="amplify">
Would work.
I also sometimes like to add a form field for the 'counter' on the processing page
<input type="hidden" name="counter" value="#client_admin_surveys.recordCount#" />
Then on the processing page, you can loop over the counter and access the form fields using bracket notation
<cfloop from="1" to="#form.counter#" indexd="i">
<cfset thisAmplify = form["amplify" & i] />
<cfset thisEnhance = form["enhance" & i] />
<!---- more logic here --->
</cfloop>
这篇关于访问动态形式的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!