Created
November 2, 2015 08:56
-
-
Save levantoan/ebda7a8d28808d12a13c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Add to functions.php | |
*/ | |
function comment_validation_init() { | |
if(is_singular() && comments_open() ) { ?> | |
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script> | |
<script type="text/javascript"> | |
jQuery(document).ready(function($) { | |
$('#commentform').validate({ | |
onfocusout: function(element) { | |
this.element(element); | |
}, | |
rules: { | |
author: { | |
required: true, | |
minlength: 2 | |
}, | |
email: { | |
required: true, | |
email: true | |
}, | |
comment: { | |
required: true, | |
} | |
}, | |
messages: { | |
author: "Please enter in your name.", | |
email: "Please enter a valid email address.", | |
comment: "Message box can't be empty!" | |
}, | |
errorElement: "div", | |
errorPlacement: function(error, element) { | |
element.after(error); | |
} | |
}); | |
}); | |
</script> | |
<?php | |
} | |
} | |
add_action('wp_footer', 'comment_validation_init'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment