在jquery-form-validator插件中放置错误


<html lang="en" dir="ltr"><head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>jQuery Form Validator</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">
</head>
<form action="" id="registration-form">
<table border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td>E-mail</td>
    <td><input id="email" name="email" data-validation="email"></td>
  </tr>
  <tr>
    <td></td>
    <td><label for="email" generated="true" class="error"></label></td>
  </tr>
  <tr>
    <td>User name</td>
   <td> <input id="user" name="user" data-validation="length alphanumeric" 
         data-validation-length="3-12" 
         data-validation-error-msg="User name has to be an alphanumeric value (3-12 chars)"></td>
  </tr>
  <tr>
    <td></td>
    <td><label for="user" generated="true" class="error"></label></td>
  </tr>
  <tr>
    <td>Password</td>
    <td><input id="pass_confirmation" name="pass_confirmation" data-validation="strength" 
         data-validation-strength="2"></td>
  </tr>
  <tr>
    <td></td>
    <td><label for="pass_confirmation"></label></td>
  </tr>
  <tr>
    <td>Repeat password</td>
    <td><input name="pass" data-validation="confirmation"></td>
  </tr>
  <tr>
    <td>Birth date</td>
    <td><input name="birth" data-validation="birthdate" 
         data-validation-help="yyyy-mm-dd"></td>
  </tr>
  <tr>
    <td>Country</td>
    <td><input name="country" id="country" data-validation="country"></td>
  </tr>
  <tr>
    <td>Profile image</td>
     <td><input name="image" type="file" data-validation="mime size required" 
         data-validation-allowing="jpg, png" 
         data-validation-max-size="300kb" 
         data-validation-error-msg-required="No image selected"></td>
  </tr>
  <tr>
    <td>User Presentation (<span id="pres-max-length">100</span> characters left)</td>
    <td><textarea name="presentation" id="presentation"></textarea></td>
  </tr>
  <tr>
    <td colspan="2"><input type="checkbox" data-validation="required" 
         data-validation-error-msg="You have to agree to our terms">
    I agree to the <a href="..." target="_blank">terms of service</a></td>
  </tr>
  <tr>
    <td><input type="submit" value="Validate"></td>
    <td><input type="reset" value="Reset form"></td>
  </tr>
</table>  
</form>
</body>
<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.2.1/jquery.form-validator.min.js"></script>
<script>
  $.validate({
    modules : 'location, date, security, file',
    onModulesLoaded : function() {
      //$('#country').suggestCountry();
    }
  });
  // Restrict presentation length
  $('#presentation').restrictLength( $('#pres-max-length') );
</script>
</html>

我正在研究表单验证,一段时间后,我发现jquery-表单验证器插件,这将有助于我验证。但现在我正试图找出如何改变错误的位置。现在所有的错误都显示在字段名前面。我想在

中显示email的错误

<label for="user" generated="true" class="error"></label>

还有PHP的表单验证吗

使用属性data-validation-error-msg-container指出某个输入的错误消息的位置

<input data-validation="..." 
       data-validation-error-msg-container="#some-where-else" />
<div id="some-where-else"></div>

当涉及到这个问题时,你还有一些其他的选择。您可以在http://formvalidator.net/#configuration_position

上阅读相关内容

用户可以在这里参考他们的文档http://formvalidation.io/examples/showing-message-custom-area/查看自定义错误信息区域

或者您可以使用以下代码:

err: {
        container: '#messages'
    },

您可以在jQuery验证插件的每个字段的代码中尝试这段代码。

相关内容

  • 没有找到相关文章

最新更新