Skip to content

Instantly share code, notes, and snippets.

@aayushdrolia
Last active October 14, 2022 06:59
Show Gist options
  • Save aayushdrolia/23b40152f34fa790773ea894fd4d6091 to your computer and use it in GitHub Desktop.
Save aayushdrolia/23b40152f34fa790773ea894fd4d6091 to your computer and use it in GitHub Desktop.
Comment form validation message on the same page in wordpress
***********************************************
PHP CODE (add it in your theme's functions.php)*
***********************************************
function insert_jquery_validate(){
wp_enqueue_script('validate', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js', array( 'jquery' ), false, true );
}
add_filter('wp_enqueue_scripts','insert_jquery_validate');
************************************
jQuery code add it in your js file *
************************************
function resetForm(){
$('#fl-comment-form').reset();
validator.resetForm();
}
function validateForm(){
if (validator.form()) {
$('#fl-comment-form').submit();
}
}
validator = $("#fl-comment-form").validate({
rules: {
author: "required",
email: {
required: true,
email: true
},
url: {
url: true
},
comment: "required"
},
messages: {
author: "Please enter your name",
email: {
required: "Please enter an email address",
email: "Please enter a valid email address"
},
url: "Please enter a valid URL e.g. http://www.mysite.com",
comment: "Please include your comment"
}
});
@kise19
Copy link

kise19 commented Oct 14, 2022

Thanks for sharing the code. It's useful much flagle unlimited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment