Last active
October 14, 2022 06:59
-
-
Save aayushdrolia/23b40152f34fa790773ea894fd4d6091 to your computer and use it in GitHub Desktop.
Comment form validation message on the same page in wordpress
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 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" | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing the code. It's useful much flagle unlimited.