简体   繁体   English

jQuery Nice Form验证插件

[英]Jquery Nice Form Validation Plugin

I have found a nice form validation plugin in this website: http://formvalidator.net/index.html 我在此网站上找到了一个不错的表单验证插件: http : //formvalidator.net/index.html

While I was trying to implement server-side validation, the plugin doesn't seems to work. 当我尝试实现服务器端验证时,该插件似乎无法正常工作。 It states that it would send the url via POST method to the url that I have declared in the attribute data-validation-url.However when I tried to echo the post variable, it doesn't seems to show in the web browser. 它声明它将通过POST方法将URL发送到我在data-validation-url属性中声明的URL,但是当我尝试回显post变量时,它似乎没有显示在Web浏览器中。

Could someone help to look into it? 有人可以帮忙调查一下吗? Maybe I might have done something wrong somewhere. 也许我在某处做错了。 Apologies, I am quite new to programming! 抱歉,我是编程新手! :) :)

Take a look at this page section: http://formvalidator.net/index.html#security-validators 请看此页面部分: http : //formvalidator.net/index.html#security-validators

FormValidate.html FormValidate.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="form-validator/jquery.form-validator.min.js"></script>
<script>
$.validate
  ({
   modules : 'security',
   onModulesLoaded : function() 
 {
$('input[name="pass"]').displayPasswordStrength();
 }
  });
</script>

</head>
<body>
    <form action="" id='form'>
        <p>
           <label>User name:</label>  
 <input name="user" data-validation="server" data-validation-url="validateInput.php" />
        </p>

 <p>
   <label>Password:</label>
   <input  name="pass" data-validation="strength" data-validation-strength="2"   type="password">

</p>
<p><i>Hint: A strong password consists of 13 alphanumeric characters.</i></p>

 <label> Confirm password:</label>
<input name="pass_confirmation" data-validation="confirmation" type='password'>
 <p>
 <input type="submit">
 </p>
  </form>   
 </body>
 </html>

validate.php validate.php

<?php
 $response = array(
 'valid' => false,
'message' => 'Post argument "user" is missing.'
                  );

 if( isset($_POST['user']) ) {
    echo $_POST['user'] //value not echoed in the browser :/
                            }
 echo json_encode($response);

EDITED: I missed completely a slash in the input of the username, and that was the problem, test it now, now it fires the post request. 编辑:我完全错过了用户名输入中的斜杠,这就是问题所在,现在进行测试,现在它会触发发布请求。

You only need to add method post on the form. 您只需要在表单上添加方法发布。

Try to use proper indentation it's easier to read and no one will blame you for doing it. 尝试使用适当的缩进更容易阅读,没有人会责怪您这样做。

 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.1.47/jquery.form-validator.min.js"></script> <script> $.validate({ modules : 'security', onModulesLoaded : function() { var optionalConfig = { fontSize: '12pt', padding: '4px', bad : 'Very bad', weak : 'Weak', good : 'Good', strong : 'Strong' }; $('input[name="pass"]').displayPasswordStrength(optionalConfig); } }); </script> </head> <body> <form action="/login" id='form'> <p> <label>User name:</label> <input name="user" data-validation="server" data-validation-url="validateInput.php"> </p> <p> <label>Password:</label> <input name="pass" data-validation="strength" data-validation-strength="2" type="password"> </p> <p> <i>Hint: A strong password consists of 13 alphanumeric characters.</i> </p> <label> Confirm password:</label> <input name="pass_confirmation" data-validation="confirmation" type='password'> <p> <input type="submit"> </p> </form> </body> </html> 

Check this out, seems to be working fine. 检查一下,似乎工作正常。

Good Luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM