问题描述
我的表格是:
。我在Coldfusion中创建了一个调查工具。
-
t_forms
(id,name,desc) -
t_questions
(id,question,type,formid,order) -
t_cdata
) -
t_cqdata
(formid,questionid,customerid,answergiven)
表单字段使用url变量动态构建,例如:
< cfquery name =gs>
select * from t_forms其中id =#url.sid#
< / cfquery>
< cfquery name =gq>
select * from t_questions其中fid =#gs.id#ORDER BY order ASC
< / cfquery>
< cfform name =surveymethod =postaction =>
< cfloop query =gq>
< cfinput type =textname =q#gq.id#>
< / cfloop>
< cfinput type =textname =email>
< cfinput type =hiddenname =fidvalue =#url.fid#>
< cfinput type =submitname =submitvalue =Save>
< / cfform>
但是,当我需要将答案的值放入 t_cqdata
表,因为表单元素输入也需要进入表。
如果任何人可以帮助或指出
有多种方法可以使表单字段与数据库标识符相关联值。这是我发现最容易理解的一个。
在表单页面上。
< cfoutput query =somequery>
< input name =field1#databaseID#>
< input name =field2#databaseID#>
等
< cfloop list =#form.fieldnames#index =ThisElement>
< cfif left(ThisElement,6)isfield1>
< cfset ThisID = RemoveChars(ThisElement,1,6)>
< cfset ThisField1Value = form [ThisElement]>
< cfset ThisField2Value = form ['field2'& ThisID]>
继续设置变量,然后对它们进行操作。事实上,在这个例子中,一旦你设置了 ThisID
,设置更多的变量是可选的。您可以直接使用所显示的synax直接使用表单变量。
I'm trying to create a survey tool in Coldfusion and I'm stuck on one part.
My tables are:
t_forms
(id, name, desc)t_questions
(id, question, type, formid, order)t_cdata
(id, email)t_cqdata
(formid, questionid, customerid, answergiven)
The form fields are dynamically built using a url variable and look like this, for example:
<cfquery name="gs">
select * from t_forms where id = #url.sid#
</cfquery>
<cfquery name="gq">
select * from t_questions where fid = #gs.id# ORDER BY order ASC
</cfquery>
<cfform name="survey" method="post" action="">
<cfloop query="gq">
<cfinput type="text" name="q#gq.id#">
</cfloop>
<cfinput type="text" name="email">
<cfinput type="hidden" name="fid" value="#url.fid#">
<cfinput type="submit" name="submit" value="Save">
</cfform>
However, I'm having trouble when I need to put the value of the answer into the t_cqdata
table, as the form element input needs to go into the table as well.
If anyone could help or point out where I am going wrong, that would be appreciated .
There is more than one way to have form fields associated with database identifier values. This is the one I find easiest to comprehend.
On the form page.
<cfoutput query="somequery">
<input name="field1#databaseID#">
<input name="field2#databaseID#">
etc
On the processing page.
<cfloop list="#form.fieldnames#" index="ThisElement">
<cfif left (ThisElement, 6) is "field1">
<cfset ThisID = RemoveChars(ThisElement, 1, 6)>
<cfset ThisField1Value = form[ThisElement]>
<cfset ThisField2Value = form['field2' & ThisID]>
Continue to set variables and then do something with them. In fact, in this example, once you've set ThisID
, setting more variables is optional. You can simply use the form variables directly using the synax shown.
这篇关于使用Coldfusion创建调查:停留在表数据插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!