2016-03-15 22 views
0

Hy! 我做了一個簡單的表單,幷包括我的js驗證文件,但它不工作。 我甚至包括所有必需的腳本和css文件,但它給出了錯誤。 在控制檯上的錯誤是表單驗證不起作用

最大調用堆棧大小超過

我沒有找到任何解決辦法呢!

form_validation.js

$(document).ready(function() { 


    $('#contactForm') 
     .formValidation({ 
      icon: { 
       valid: 'glyphicon glyphicon-ok', 
       invalid: 'glyphicon glyphicon-remove', 
       validating: 'glyphicon glyphicon-refresh' 
      }, 
      fields: { 
       name: { 

        validators: { 
         notEmpty: { 
          message: 'The first name is required' 
         }, 
        regexp: { 
         message: 'Name only contains Letter', 
         regexp: /^[A-Za-z]*$/ 
        } 

        } 
       }, 
       message: { 
        validators: { 
         notEmpty: { 
          message: 'The message is required' 
         }, 
        } 
       } 

      } 
     }) 

}); 

testForm.php

<!DOCTYPE html> 
<!-- 
To change this license header, choose License Headers in Project Properties. 
To change this template file, choose Tools | Templates 
and open the template in the editor. 
--> 
<html> 
    <head> 
     <meta charset="UTF-8"> 
     <title></title> 
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> 
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/ecmascript"></script> 
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
    <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> 

<script src="http://formvalidation.io/vendor/formvalidation/js/formValidation.min.js"></script> 

<script src="http://formvalidation.io/vendor/formvalidation/js/framework/bootstrap.min.js"></script> 
<script src="js/form_validation.js"></script> 

    </head> 
    <body> 
     <form method="post" id="contactForm" > 
     <label>Name</label> 
     <input type="text" name="name"/> 
     <input type="submit" value="process"/> 
    </form> 

    </body> 
</html> 
+0

我舉辦了一個猜測。 請改變這個標記的名稱屬性的值 不要忘記在form_validation.js中更改.. :) –

回答

1

由於您使用的引導味道formvalidation它讓你的標誌了一定的假設。

如果你將自己的表單控件包裝在引導類中,它應該可以工作。

此外,你正在refencing你的JavaScript中的消息字段不存在於您的標記。

嘗試這樣:

<form method="post" id="contactForm" > 

    <div class="form-group"> 
     <label for="name">Name</label> 
     <input class="form-control" type="text" name="name" id="name"/> 
    <div> 

    <div class="form-group"> 
     <label for="message">Message</label> 
     <input class="form-control" type="text" name="message" id="message"/> 
    </div> 

    <input class="btn btn-default" type="submit" value="process"/> 

</form> 
+0

我知道通過添加引導類,它會工作,但如果我想在覈心php上運行相同的驗證呢? –

+0

然後你使用了錯誤的庫。 Formvalidation適用於Bootstrap,Foundation,Pure,Semantic或UIKit。如果你想在沒有任何框架的情況下使用它,你最好使用jQuery驗證或者類似的東西。你也可以推出自己的產品,但可能需要一些工作。看看這裏,如果你有興趣沿着這條路走下去:http://formvalidation.io/examples/#supporting-other-frameworks-and-form-b​​uilders – Robban

+0

謝謝親愛的。 上帝保佑你 –