2014-10-30 58 views
1

我使用contact_me.js和contact_me.php引導contact_form來提交我的聯繫表單。我遇到的問題是我有一個頁面的網站,進一步的頁面是一個貝寶按鈕。當我點擊貝寶按鈕時,它正在提交聯繫表單。從另一個按鈕提交bootstrap contact_me

我試圖做一個對PayPal按鈕「返回false」停止這一點,然後有PayPal按鈕點擊該提交貝寶形式

我的繼承人貝寶形式的jQuery函數

<form action="https://www.paypal.com/cgi-bin/webscr" name='paypalForm' method="post"> 
    <input type="hidden" name="cmd" value="_s-xclick"> 
    <input type="hidden" name="hosted_button_id" value="G8FJ3NGXWAE6G"> 
    <input type="hidden" name="on0" value="Reservations">Reservations:<br /> 

    <select name="os0"> 
    <option value="One Bike">One Bike &euro;300.00</option> 
    <option value="Two Bikes">Two Bikes &euro;600.00</option> 
    <option value="Three Bikes">Three Bikes &euro;900.00</option> 
    </select> 
    <input type="hidden" name="currency_code" value="EUR"><br /> 
    <input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="button" onclick="return false;"id='paypalButton' alt="PayPal - The safer, easier way to pay online."> 
    <img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/en_GB/i/scr/pixel.gif" width="1" height="1"> 
</form> 

我的繼承人上點擊功能的jQuery(我把警報,以檢查它被稱爲)

$("#paypalButton").click(function() {  
      alert('here'); 
      $("#paypalForm").submit(); 
     }); 

這裏是被稱爲contact_me.js的開放,如果我不哈VE一對PayPal按鈕

$("input,textarea").jqBootstrapValidation({ 
    preventSubmit: true, 
    submitError: function($form, event, errors) { 
     // something to have when submit produces an error ? 
     // Not decided if I need it yet 
    }, 
    submitSuccess: function($form, event) { 
     event.preventDefault(); // prevent default submit behaviour 
     // get values from FORM 
     var name = $("input#name").val(); 
     var phone = $("input#phone").val(); 
     var email = $("input#email").val(); 
     var message = $("textarea#message").val(); 
     var firstName = name; // For Success/Failure Message 
     // Check for white space in name for Success/Fail message 
     if (firstName.indexOf(' ') >= 0) { 
      firstName = name.split(' ').slice(0, -1).join(' '); 
     }......... etc 

我怎樣才能得到PayPal按鈕無需提交聯繫表單「返回false」?

我是否必須更改contact_me.js(以及如何)或者可以從$('#paypalButton')。click()?

回答

3

我通過向contactme添加表單的名稱來解決此問題。js文件,以便提交調用是這樣

$('form[name="sentMessage"]').find("input,textarea").jqBootstrapValidation({ 

代替

$("input,textarea").jqBootstrapValidation({ 

現在它工作正常

1

好的,所以我試了一下。我必須承認,我對js是全新的,不知道下面的解決方案是否是防彈的,但是我的PayPal按鈕和contactform現在都在工作。以下是我所做的:

我瀏覽了jqBootstrapValidation.js文件並逐漸禁用了它的部分內容,直到找到使我的PayPal按鈕再次運行的位置。我發現如果js文件的第49行:

var $inputs = $form.find("input,textarea,select").not("[type=submit],[type=image]").filter(settings.options.filter); 

被禁用,PayPal按鈕工作正常。

所以下次我包了var成if語句看起來像這樣:

if (
    $form.hasClass("contactform") 
    ) { 
    var $inputs = $form.find("input,textarea,select").not("[type=submit],[type=image]").filter(settings.options.filter); 
     } 

所以基本上現在需要在HTML文件中的類「聯繫形式」來設置變量$輸入。

我的聯繫形式HTML看起來像現在這樣:

<div class="col-sm-offset-3 col-lg-6"> 
    <form name="sentMessage" id="contactForm" class="contactform" novalidate> 
     <legend class="content-legend">Kontakt</legend> 
     <div class="control-group"> 
      <div class="controls"> 
       <input type="text" class="form-control content-form" placeholder="Name" id="name" required data-validation-required-message="Bitte geben sie Ihren Namen ein" /> 
      </div> 
     </div> 
     <div class="control-group"> 
      <div class="controls"> 
       <input type="email" class="form-control content-form" placeholder="Mail" id="email" required data-validation-required-message="Bitte geben Sie eine Mailadresse ein" /> 

[...]等

例如該表單包含「contactform」類。

我的PayPal按鈕的HTML如下:

<form target="_blank" action="https://www.paypal.com/cgi-bin/webscr" method="post" id="paypalbutton" target="_top" style="float:right;"> 
    <input type="hidden" name="cmd" value="_s-xclick"> 
    <input type="hidden" name="hosted_button_id" value="xxx"> 
    <input type="submit" value="Jetzt zahlungspflichtig Bestellen" border="0" name="submit" title="Jetzt einfach, schnell und sicher online bezahlen – mit PayPal." class="btn btn-primary"> 
    <img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1"> 
</form> 

例如該表單不包含「contactform」類。 var $輸入不會被jqBootstrapValidation.js文件設置,因此它不會觸發阻止PayPal按鈕工作的事件。

我希望它有幫助。