2011-09-07 30 views
0

我有一個帶有兩個提交按鈕的cfform,我的操作頁面中的邏輯完全適用於safari,chrome,FF和IE9。但IE8和更少有問題。在IE8或更少由於某種原因它似乎無法發送操作頁面的提交按鈕的值,所以它永遠不會使它在我的任何if語句。ColdFusion Internet Explorer Form提交問題

表格代號:

<cfform action="appQuery.cfm?loc=personal" method="post" data-ajax="false"> 
      <label for="fName">First Name</label> 
      <cfinput type="text" name="fName" value="#fName#" style="width: 200px;"><br> 
      <label for="MI">Middle Initial</label> 
      <cfinput type="text" name="MI" value="#MI#" maxlength="1" style="width: 40px;"><br> 
      <label for="lName">Last Name</label> 
      <cfinput type="text" name="lName" value="#lName#" style="width: 200px;"><br> 
      <label for="dob">Date Of Birth Ex. 03/13/94</label> 
      <cfinput type="text" name="dob" maxlength="8" value="#dob#" style="width: 100px;"><br> 
      <fieldset data-role="controlgroup" data-type="horizontal" > 
       <legend>Gender</legend> 
       <label for="1">Female</label> 
       <input type="radio" value="Female" name="gender" id="1" <cfif #gender# eq "Female">checked</cfif> > 
       <label for="2">Male</label> 
       <input type="radio" value="Male" name="gender" id="2" <cfif #gender# eq "Male">checked</cfif>> 
      </fieldset> 
      <div data-role="fieldcontain"> 
       <label for="ethnicity" class="select">Choose Ethnicity</label> 
       <select name="ethnicity" id="ethnicity" data-native-menu="false" data-inline="true" class="eth" onChange="change()"> 
        <option value="Hispanic" <cfif #Ethnicity# eq "Hispanic">selected</cfif>>Hispanic</option> 
        <option value="African American" <cfif #Ethnicity# eq "African American">selected</cfif>>African American</option> 
        <option value="Asian/Pacific Islander" <cfif #Ethnicity# eq 'Asian/Pacific Islander'> selected</cfif>>Asian/Pacific Islander</option> 
        <option value="Caucasian" <cfif #Ethnicity# eq "Caucasian"> selected</cfif>>Caucasian</option> 
        <option value="Other" id="other">Other</option> 
       </select> 
      </div> 
      <div id="ethCustom" style="visibility:hidden;" data-role="fieldcontain"> 
       <label for="ethOther">Ethnicity</label> 
       <cfinput type="text" name="ethOther" style="width: 200px;" /><br> 
      </div> 
      <cfinput type="submit" data-inline="true" value="Save and Contiune Later" name="submit" /> 
      <cfinput type="submit" data-inline="true" value="Save and Contiune Now" name="submit" /> 
     </cfform> 

行動頁:

<cfif #URL.loc# eq "personal" AND #FORM.submit# eq "Save and Contiune Now"> 
    <cfquery datasource="#dbname#" username="#dbuser#" password="#dbpass#" name="personal1"> 
    UPDATE student 
    SET fName = '#FORM.fName#', lName = '#FORM.lName#', MI = '#FORM.MI#', dob = '#FORM.dob#', gender = '#FORM.gender#',<cfif #FORM.ethnicity# eq "Other"> Ethnicity = '#FORM.ethOther#'<cfelse> Ethnicity = '#FORM.ethnicity#'</cfif> 
    WHERE s_id = '#COOKIE.id#' 
    </cfquery> 
    <cflocation url="appProcess.cfm##contact" addtoken="no"> 
<cfelseif #URL.loc# eq "personal" AND #FORM.submit# eq "Save and Contiune Later"> 
    <cfquery datasource="#dbname#" username="#dbuser#" password="#dbpass#"> 
    UPDATE student 
    SET fName = '#FORM.fName#', lName = '#FORM.lName#', MI = '#FORM.MI#', dob = '#FORM.dob#', gender = '#FORM.gender#',<cfif #FORM.ethnicity# eq "Other"> Ethnicity = '#FORM.ethOther#'<cfelse> Ethnicity = '#FORM.ethnicity#'</cfif> 
    WHERE s_id = '#COOKIE.id#' 
    </cfquery> 
    <cflocation url="http://.com/logout.cfm" addtoken="no」> 
</cfif> 

是否有不同的方式,我可以有條件地檢查其提交按鈕被按下的是IE瀏覽器友好嗎?

回答

1

請檢查下列編碼。希望它能幫助你。

表Page

<script> 
<!-- 
    function clickbtnSubmit(obj) { 
     document.myForm.btnPress.value = obj; 
    } 
--> 
</script> 

<cfform name="myForm" action="[yourActionPage]" method="post" data-ajax="false"> 
    <input type="Hidden" name="btnPress"> 
    ... 
    ... 
    ... 
    <cfinput type="submit" data-inline="true" value="Save and Contiune Later" onclick="clickbtnSubmit(this.value)" name="submit" /> 
    <cfinput type="submit" data-inline="true" value="Save and Contiune Now" onclick="clickbtnSubmit(this.value)" name="submit" /> 
</cfform> 

操作Page

<cfdump var="#form#"> 
+0

中使用maxlength幾個問題可能是愚蠢的問題,但爲什麼是html註釋中的函數?還有,cfdump標籤有什麼作用? – rajh2504

+0

請勿使用HTML評論。我把是讓你知道哪個提交按鈕被按下。 – ppshein

0

您可以將提交更改爲按鈕,然後在按下按鈕時捕獲onclick,更改隱藏的表單字段,然後提交。

或者,只需將兩個提交按鈕更改爲無線電輸入?

+0

我可能要指出的是好吧,你的cfquery中有你的參數值,這會導致SQ L注射..你剛剛發佈你的網址。 –

+0

我是coldfusion的新手,cfqueries中的參數化值是什麼?你也可以告訴我僞代碼JavaScript的答案我很難弄清楚這個函數將如何工作。 – rajh2504

+2

內,您的CFQUERY的的,這樣做: UPDATE學生 集FNAME =

0

不知道這將幫助:我使用的是IE瀏覽器版本8.0.6001.18702,我注意到提交按鈕不當我按下回車鍵而不是按下「提交」按鈕時通過。我在Chrome或Firefox中沒有這個問題。一個簡單的解決方法是創建一個隱藏的虛擬字段來傳遞和檢查值,只需要添加一行並在同一CF頁面上更改一行。

的2行是:
1.通過添加其中傳遞隱藏字段中的一個線上的虛擬字段的傳(見下到最後一行;我使用的變量名輸入)
2.添加的檢查在你的代碼的頂部的虛擬價值,「form.enter」的存在(見的樣本第一行代碼)

示例代碼:my_edit_page.cfm

<cfif isdefined("form.update") OR isdefined("form.enter")> 
    <cfquery datasource="my_datasource" result="sqlerrm"> 
     [enter your SQL here] 
    </cfquery> 
    <cflocation url="my_edit_page.cfm?id=#url.id# /> 
</cfif> 
: 
:    
<cfform action="my_edit_page.cfm" method="post"> 

     : 
    <input type="submit" class="btn btn-primary" name="update" value="Update" /> 
    <input type="hidden" name="my_field" value="#myquery.my_field#" /> 
    <input type="hidden" name="enter" value="enter" /> 
</cfform> 
: