ColdFusion how to set form input values from the results of a cfquery?(ColdFusion如何从cfquery的结果中设置表单输入值?)
问题描述
问题:(第 1 部分)我正在寻找基于 cfquery
的结果设置表单输入值的最有效方法.我的表单字段都与数据库中的列名匹配.我知道使用 cfinsert
我可以使用表单输入值更新数据库.有没有办法反过来做?
Question: (part 1) I am looking for the most efficient way to set my form input values based on the results of my cfquery
. My form fields all match the column names in the database. I know using cfinsert
I can update the database with form input values. Is there a way to do that in reverse?
(第 1.5 部分)如何根据我的 cfquery 的值设置选择和单选按钮的值?
(part 1.5) How do I set the values of select and radio buttons based on the value of my cfquery?
背景:我有一个包含 60 多个输入的表单,其中包含 text
、select
、radio
和 textarea
.我正在创建的页面是允许用户查看他们之前提交的答案,并允许他们进行更改并再次提交表单,并使用他们的新答案(如果有的话)更新数据库.
Background: I have a form with 60+ inputs with a mixture of text
, select
, radio
and textarea
. The page I'm creating is to allow the user to review the answers they have submitted previously and allow them to make changes and submit the form again and update the database with their new answers (if any).
以下只是输入的一小部分示例,除非有不同的方式,否则我将如何设置值.
Below is just a small sample of inputs and I how I will set the value unless there is a different way.
<!--variables pulled from the URL-->
<cfset pageAction="#URL.action#">
<cfset rfqID="#URL.rfqID#">
<cfset rfqStatus="#URL.status#">
<!--Query to get previous form answers -->
<cfquery name="getFormData" datasource="RC">
SELECT *
FROM RFQ_Data
WHERE form_ID = <cfqueryparam value="#ARGUMENTS.rfqID#">
</cfquery>
<cfform name="rfq_form" class="pure-form pure-form-aligned" enctype="multipart/form-data" action="rfq_action.cfm" method="POST">
<cfoutput>
<label>*Sold to Party:</label>
<cfinput type="text" name="sold_to_party" value="#getFormData.sold_to_party#"/>
<!--HOW DO I SET THE DEFAULT VALUE OF MY SELECT TO BE THE VALUE FOUND IN THE CFQUERY?-->
<label>*Product Type:</label>
<select name="product_category" id="product_category">
<option value="ts8-it">TS8-Data Center </option>
<option value="ts8-ie">TS8-Industrial </option>
<option value="WM_AE_JB">WM/AE/JB </option>
<option value="other">Other </option>
</select>
<h3>Additional information:</h3>
<textarea name="additional_info_datacenter" rows="10" cols="60" style="margin-left:40px;">#getFormData.additional_info_datacenter#</textarea>
<!--HOW DO I SET THE DEFAULT VALUE OF MY RADIO TO BE THE VALUE FOUND IN THE CFQUERY?-->
<label>19" Rails</label>
<input id="rails_yes" type="radio" name="19_Rails" value="yes"> YES
<input id="rails_no" type="radio" name="19_Rails" value="no"> NO
</cfoutput>
<cfinput style="padding:4px 6px;" type="submit" value="Submit Current Order" name="submit"/>
</cfform>
推荐答案
对于选择,您可以尝试比较每个选项值,例如:
for select you can try a comparison for each option values like:
<select name="product_category" id="product_category">
<option value="ts8-it" <cfif CompareNoCase(getFormData.product_category,"ts8-it") EQ 0>selected="selected"</cfif> >TS8-Data Center </option>
同样的方式你可以尝试无线电场,
Same way you can try the radio fields,
<input id="rails_yes" type="radio" name="19_Rails" value="yes" <cfif getFormData.19_Rails>checked="checked"</cfif> >
<input id="rails_no" type="radio" name="19_Rails" value="no" <cfif NOT getFormData.19_Rails>checked="checked"</cfif> >
这篇关于ColdFusion如何从cfquery的结果中设置表单输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ColdFusion如何从cfquery的结果中设置表单输入值?


- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Flexslider 箭头未正确显示 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01