dszpyf4859 2017-03-01 15:30
浏览 26
已采纳

Bootstrap validator.js没有与我的PHP通信

I'm a novice coder, and i'm having trouble putting a simple form together using validator.js

Basically since trying to build in the validation the form has stopped working, my guess is the 'data: $('#send-form').serialize(),' has not got the correct path or syntax, but i could be wrong.

As soon as i add:

$.ajax({
type: "POST",
url: "process.php",
data: $('#send-form').serialize(),
}

the alerts do not fire!

<form class="contact" name="contact" id="send-form" data-toggle="validator" role="form"  >


  <div class="form-group">
    <label class="subTitle" for="name">NAME</label><br>
    <input type="text" name="name" class="form-control" placeholder="Enter your full name" data-error="Please enter your name" required>
    <div class="help-block with-errors"></div><br>
  </div>

  <div class="form-group">
    <label class="subTitle" for="email">E-MAIL</label><br>
    <input type="email" name="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" class="form-control" placeholder="Enter a valid email address" data-error="Invalid email address" required>
    <div class="help-block with-errors"></div><br>
  </div>

    <div class="form-group">
      <button type="submit" class="subBtn form-control">SUBMIT YOUR ENQUIRY</button>
    </div>

</form> 




    



<script>
$('#send-form').validator().on('submit', function (e) {
    if (e.isDefaultPrevented()) {
        alert('form is not valid');
    } else {
        // everything looks good!
        e.preventDefault();
        alert('form is valid');
        // your ajax
                $.ajax({
                type: "POST",
                url: "process.php",
                data: $('#send-form').serialize(),
                }
});

</script>

</div>
  • 写回答

1条回答 默认 最新

  • dongxia19772008 2017-03-01 15:38
    关注

    Should be:

    $('#send-form').validator().on('submit', function (e) {
        if (e.isDefaultPrevented()) {
            alert('form is not valid');
        } else {
            // everything looks good!
            e.preventDefault();
            alert('form is valid');
            // your ajax
            $.ajax({
                type: "POST",
                url: "process.php",
                data: $('#send-form').serialize(),
            });
        }
    });
    

    (untested)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求指导ADS低噪放设计
  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存