2

So I'm using Validate.js to validate my forms through the front-end. But for some weird reason the errors are not being displayed. I'm also not sure if they're being validated to begin with. Any ideas?

Heres my code:

<html>
<head>
<script type="text/javascript" src="validate.js"></script>
</head>
<body>
<form id="form1">
<input type="text" name="name" placeholder="Name"><br>
<input type="text" name="email" placeholder="Email"><br>
<input type="password" name="password" placeholder="Password"><br>
<input type="submit" value="Submit">
 </form>
  <script>
var validator = new FormValidator('form1', [{
    name: 'name',
    display: 'required',
    rules: 'required'
}, {
    name: 'email',
    rules: 'valid_email'
}, {
    name: 'password',
    rules: 'required'
}, {
    name: 'password_confirm',
    display: 'password confirmation',
    rules: 'required|matches[password]'
}], function(errors, event) {
    if (errors.length > 0) {
        // Show the errors
    }
});
</script>
 </body>
 </html>
2
  • Any errors in the Javascript console? Commented May 10, 2014 at 1:27
  • Nothing is displaying. @Barmar Commented May 10, 2014 at 1:28

1 Answer 1

1

According to the documentation in the validate.js page:

The formName passed in to validate must be the exact value of the name attribute of the form

You are using the id of the form instead of the name in the validator variable. You need to add a name to your form and use it in your variable:

<form id="form1" name="myForm">
[...]
<script>
var validator = new FormValidator('myForm', [{
[...]

Hope it helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.