访问动态表单的变量 [英] Accessing variables of a dynamic form

查看:19
本文介绍了访问动态表单的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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.

这是我的表格:

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

发布表单后,结果会将我的所有选择分组,因为我的表单元素具有相同的名称".我尝试在每个名称旁边添加一个 i 计数以使其不同,但后来我对如何处理这些字段有点困惑.

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

会工作的.

我有时也喜欢在处理页面上为计数器"添加一个表单域

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

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