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的结果中设置表单输入值?
基础教程推荐
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01