Created
November 29, 2022 10:57
-
-
Save developer-anuragsingh/5edc29286d712f5c12b25746fb534ade 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 | |
/** | |
* 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