I want to display comment form validation errors (as well as captcha error) on the comment form itself and not on a different page. How can I do that?
2 Answers
This question have answered again, here
Also you can do the same with JQuery and Validation plugin
You not to do anything other than install comment form JS validation plugin. Click here and download.
-
Used the jquery with some extra configuration and captcha adjustments Commented Jan 27, 2011 at 2:40
I was facing same problem and was searching for solution i found the solution
Open your function.php file and past below code:
function comment_validation_init() {
if(is_single() && comments_open() ) { ?>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/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 fill the required field",
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', 'comment_validation_init');
For giving style:
.error { padding: 10px 0 20px 0; color: #FF0000; }
input.error, textarea.error { color:#000000; }
-
2Please add an explanation. What does your code exactly? And never use the wrong jQuery version, always enqueue the built-in jQuery.– fuxia ♦Commented Jan 31, 2014 at 7:35
-
It's important to point out that you're using the validate plugin here Commented Jul 21, 2019 at 9:16