2015-09-22 142 views
1

我使用的引導彈出模態的形式在我的網站作爲接觸form.I使用引導形式validation.Now我想提交表單,並顯示在同一個模式成功或錯誤信息做表單驗證形成。引導表單驗證並提交使用引導驗證

enter image description here

我沒有使用

<script src="js/bootstrapValidator.min.js" type="text/javascript"></script> 
<script> 
$('#contest-form').bootstrapValidator(); 
</script> 
+0

我認爲頭應該說「聯繫表」,而不是「競賽形式」 –

+0

Ajax是你正在尋找 – Shehary

回答

2

你要使用Ajax進行驗證。中的JavaScript如下(:這是利用一個元件與result的ID來顯示結果):

$('body').on('success.form.bv', '#form', function(event) { 

    event.preventDefault(); 

    var formData = $(this).serialize(); 

    $.ajax({ 
     url: 'form-submission.php', 
     type: 'post', 
     data: formData, 
     success: function(result) { 
      $('#result').html(result); 
     }, 
     error: function(jqXHR, textStatus, errorThrown) { 
      # error handling here 
     } 
    }) 

}); 

而PHP的粗略例如:

// do whatever with the form - you have access to $_POST 
$form_submitted = false // or true, depending on your PHP 

if ($form_submitted) { 

    echo '<div class="alert animated fadeIn alert-dismissable alert-success"><strong>Success!</strong> Indicates a successful or positive action.</div>'; 

} else { 

    echo '<div class="alert animated fadeIn alert-dismissable alert-danger"><strong>Error!</strong> There was an error submitting the form.</div>'; 

} 
+0

嗨解決thnx..i嘗試,但我要調用的AJAX功能後,才確認爲當期的...我怎麼能做到這一點。 .. – PHPCoder

+0

@PHPCoder不好意思啊 - 我已經編輯我的答案。將'submit'改成'success.form.bv'(我上面例子中的第一行) –