Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save developer-anuragsingh/5edc29286d712f5c12b25746fb534ade to your computer and use it in GitHub Desktop.
Save developer-anuragsingh/5edc29286d712f5c12b25746fb534ade to your computer and use it in GitHub Desktop.
<?php
/**
* Post's comment form validation rules
* Path : wp-content/mu-plugins/comment-form-validations.php
*/
function ans_comment_validation_rules()
{
if (is_single() && comments_open()) { ?>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$('#commentform').validate({
rules: {
author: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
comment: {
required: true,
minlength: 5
}
},
messages: {
author: "Please provide a name",
email: "Please enter a valid email address.",
comment: "Please fill the required field"
},
errorElement: "div",
errorPlacement: function (error, element) {
element.after(error);
}
});
});
</script>
<?php
}
}
add_action('wp_footer', 'ans_comment_validation_rules');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment