2015-09-22 141 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'(我上面例子中的第一行) –