Created
September 20, 2022 11:43
-
-
Save developer-anuragsingh/dbb14f0bbc83171543f364adef3b271c to your computer and use it in GitHub Desktop.
Wordpress Comment Form Validations
This file contains hidden or 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 | |
/** | |
* 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: 20 | |
} | |
}, | |
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