2017-05-25 212 views
2

我有一個表單,用戶輸入他的名字(必填),dob(不是必填項),在提交表單之前,有一個確認信息表明他/她是否確定不提交表單DOB。我使用的模式從那裏提交上面的表格。我試圖在下面運行我的代碼,但我看不出問題爲什麼不能正常工作。當dob沒有價值時,模態應該問並且說「沒有dob可以繼續嗎?」如果用戶點擊提交按鈕,那麼它應該提交上面的模式以外的表格。我希望你們幫助我。謝謝。提交之前提交的JQuery模式

HTML

<form id="createexperience" class="intro-message" method="post" action="./createexperience.php" enctype="multipart/form-data"> 
    <div class="form-group label-floating is-empty"> 
     <input type="text" name="name" required data-msg-required="Please enter your name"> 
    </div> 
    <div class="form-group label-floating is-empty"> 
     <input type="text" id="namefield" name="dob"> 
    </div> 
    <div class="form-group margin18 padbtm30"> 
    <input type="submit" class="btn btn-primary" value="Submit" /> 
    </div> 
</form> 

<div id="portfoliomsgmodal" class="modal fade" tabindex="-1"> 
<div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
      <h3 class="modal-title">TIP</h3> </div> 
     <div class="modal-body"> 
       <label>There are twice as much chances of you getting contacted by your customers if you upload something in your portfolio. Upload photos or video or audio links to your profile.</label> 
     </div> 
     <div class="modal-footer"> 
      <input type="submit" class="btn btn-warning" data-dismiss="modal" value="Now"> 
      <input type="submit" id="submitlater" class="btn btn-primary nomargin" value="Later"> 
     </div> 
    </div> 
</div> 
</div> 

jQuery的

$(document).bind("click", function (e) { 
    $("#createexperience").validate({ 
     rules: { 
      "language[]": { 
       required: !0 
      } 
     } 
     , messages: {} 
     , submitHandler: function() { 
      return !1 
     } 
     , ignore: ".ignore" 
     , errorElement: "label" 
     , errorClass: "has-error" 
     , submitHandler: function (e) { 
      if ($.trim($('#namefield').val()) == '') { 
       if (jQuery('#submitlater').data('clicked')) { 
        $('#createexperience').submit(); 
        e.submit(); 
       } 
       else { 
        $('#portfoliomsgmodal').modal('show'); 
        return false; 
       } 
      } 
      else { 
       e.submit(); 
      } 
     } 
     , highlight: function (e) { 
      $(e).closest(".form-group").removeClass("success").addClass("has-error") 
     } 
    }) 
}) 
+0

可以請您設置jsfiddle –

+0

您對此表單有什麼期待? –

+0

@bRIMOs我想使用模式按鈕提交表單(id =「createexperience」) – acmsohail

回答

2

submitHandler功能是錯誤的。試試這個代碼,希望它的作品。

$(document).bind("click", function (e) { 
    $("#createexperience").validate({ 
     rules: { 
      "language[]": { 
       required: !0 
      } 
     } 
     , messages: {} 
     , submitHandler: function() { 
      return !1 
     } 
     , ignore: ".ignore" 
     , errorElement: "label" 
     , errorClass: "has-error" 
     , submitHandler: function (e) { 
      if ($.trim($('#namefield').val()) == '') { 
       $('#portfoliomsgmodal').modal('show'); 
       $('#submitlater').click(function() { 
        e.submit(); 
       }); 
      } else { 
      e.submit(); 
      } 
     } 
     , highlight: function (e) { 
      $(e).closest(".form-group").removeClass("success").addClass("has-error") 
     } 
    }) 
}); 
+0

非常感謝你,它完美的作品:) – acmsohail

+0

隨時歡迎:) – user7152572