Skip to content

Instantly share code, notes, and snippets.

@levantoan
Created November 2, 2015 08:56
Show Gist options
  • Save levantoan/ebda7a8d28808d12a13c to your computer and use it in GitHub Desktop.
Save levantoan/ebda7a8d28808d12a13c to your computer and use it in GitHub Desktop.
<?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