ColdFusion如何从cfquery的结果设置表单输入值? [英] ColdFusion how to set form input values from the results of a cfquery?

查看:206
本文介绍了ColdFusion如何从cfquery的结果设置表单输入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:(第1部分)我正在寻找最有效的方式来设置我的表单输入值基于我的 cfquery 。我的表单字段都匹配数据库中的列名称。 我知道使用 cfinsert 我可以用表单输入值更新数据库。有没有办法做到这一点相反?



(第1.5部分)如何设置select和单选按钮的值基于我的值cfquery?



背景:我有一个包含60多个输入的表单,其中包含 text select radio textarea 。我创建的页面是允许用户查看他们以前提交的答案,并允许他们进行更改和提交表单,并更新数据库与他们的新答案(如果有)。



下面是一个小的输入示例,我将如何设置该值,除非有不同的方法。

 <! - 从URL中提取的变量 - > 
< cfset pageAction =#URL.action#>
< cfset rfqID =#URL.rfqID#>
< cfset rfqStatus =#URL.status#>

<! - 查询以获取上一个表单答案 - >
< cfquery name =getFormDatadatasource =RC>
SELECT *
FROM RFQ_Data
WHERE form_ID =< cfqueryparam value =#ARGUMENTS.rfqID#>
< / cfquery>

< cfform name =rfq_formclass =pure-form pure-form-alignedenctype =multipart / form-dataaction =rfq_action.cfmmethod =POST> ;

< cfoutput>
< label> *参加派对:< / label>

< cfinput type =textname =sold_to_partyvalue =#getFormData.sold_to_party#/>
< - - 我如何设置我的选择的默认值是在CFQUERY中找到的值?
< label> *产品类型:< / label>
< select name =product_categoryid =product_category>
< option value =ts8-it> TS8 - 数据中心< / option>
< option value =ts8-ie> TS8-Industrial< / option>
< option value =WM_AE_JB> WM / AE / JB< / option>
< option value =other>其他< / option>
< / select>


< h3>其他信息:< / h3>
< textarea name =additional_info_datacenterrows =10cols =60style =margin-left:40px;>#getFormData.additional_info_datacenter#< / textarea>
<! - 我如何设置我的无线电的默认值是在CFQUERY中发现的值?
< label> 19Rails< / label>
< input id =rails_yestype =radioname =19_Railsvalue =yes> YES
< ; input id =rails_notype =radioname =19_Railsvalue =no> NO

< / cfoutput>
< cfinput style = 4px 6px;type =submitvalue =提交当前订单name =submit/>

< / cfform>
pre>

解决方案

对于选择,您可以尝试对每个选项值进行比较,如:


$ b $ ,ts8-it)EQ 0> selected =selected< / cfif>> TS8-数据中心< / option>

以同样的方式尝试电台字段,

 < input id =rails_yes type =radioname =19_Railsvalue =yes< cfif getFormData.19_Rails> checked =checked< / cfif> > 

< input id =rails_notype =radioname =19_Railsvalue =no< cfif NOT getFormData.19_Rails> checked =checked< / cfif& >


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?

(part 1.5) How do I set the values of select and radio buttons based on the value of my cfquery?

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的结果设置表单输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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