WordPress Plugin: Comment Validation

Ever got annoyed when submitting a comment on a wordpress blog and just getting a blank page with a error message like “please fill out required fields” and nothing else? This plugin aims to help by adding validation to the comment form. When a user submits the form and something is missing, an appropiate message is displayed and individual fields are highlighted. When the email or url is in an incorrect format, a message is displayed accordingly.

Why should you install it?
Because you care for comments and want to help users reduce mistakes that hold them off from commenting at all.

Whats the technology used?
jQuery (bundled with WordPress) and the jQuery Validation plugin with a few customizations to make it fit into the standard WordPress theme.

Is it compatible with other plugins? The plugin is tested with the Draw Comments plugin and works, though the performance is slightly degraded. Other plugins haven’t yet been tested, though it now uses the wp_enqueue_script functions for the script includes, ensuring proper dependency loading.

Download WordPress-Comment-Validation-Plugin (zip)

Installation:

Download the plugin, extract it to your wp-content/plugins directory and activate it just like any other wordpress plugin (admin panel/Plugins). That’s it!


No more comments.
  1. 15. November 2008 |15:05

    Pretend for a moment that I do not have a clue as to what you are talking about.

    Sounds interesting, but I am getting rather tired of plugin developers who totally fail to explain what their plugin does in clear English. So, I am going to pass.

  2. 15. November 2008 |16:13

    hi. Thanks for plugin

    perfect.

    Regards

  3. 15. November 2008 |16:56

    @John: I’ve updated the description. Is that better?

  4. 16. November 2008 |01:52

    interesting

  5. Tim
    16. November 2008 |02:12

    Just wanted to see the all the fuz is about =)

  6. 16. November 2008 |12:16

    Will it work with the Draw Comments Plugin for WP ?

    Thanks …

    Michael Reply:

    Thanks

  7. 16. November 2008 |19:30

    @Dr-Hack: Just commited an update to improve the performance when used together with Draw Comments. It worked already but tried to validate all the hidden input elements, which was rather slow. They are now ignored.

  8. 17. November 2008 |11:13

    Nice plugin, thank you. It’s a posibillity to make it work with Math Comment Spam Protection as well?

  9. 17. November 2008 |13:50

    Thanks! The description is much better. And, the plugin is now worth trying out.

  10. Tom
    21. November 2008 |00:11

    i just installed it and it seems interesting
    nice plugin mate and new description is much better and explanative

  11. 21. November 2008 |17:32

    @Buddha: I’ve tried out that Math Comment Spam Protection and it didn’t work for me, throw some error about wrong arguments for array-rand. Not to keen to debug some random plugin.

    @John: You’re welcome.

  12. 28. November 2008 |09:55

    now this is pretty dam cool if I do say so myself, thanks guys.

  13. niko
    14. February 2009 |18:26

    nice, thank you

  14. underclass
    20. February 2009 |10:49

    Doesn’t seem to be working aat all on 2.71

  15. 27. February 2009 |12:45

    the same thing here
    doesn’t seem to be working aat all on WP 2.71

  16. Tim
    10. March 2009 |22:13

    I am trying to use your Comment Validation Plugin on a form that is displayed on a shadowbox (Fancybox Plugin). When you click the submit button the form will refresh the page without performing the validation. Do you have any experience with this problem?

  17. 15. March 2009 |17:00

    @underclass and @doron: I’ve updated the wordpress plugin to use the latest version of the validation plugin and tested with 2.7.1.

  18. Reino
    4. April 2009 |14:52

    Thanks for this great plugin! Really good work.

  19. 14. April 2009 |12:25

    Works fine on my 2.7.1, no admin screen though :S

  20. 14. April 2009 |19:32

    @Marc: What admin screen? There is no configuration for the plugin, therefore no need for an admin screen. Or is there anything you’d like to configure?

  21. 15. April 2009 |01:02

    I cannot for the life of me get this to work. I’m using 2.7.1 and no crazy plugins that I can imagine would conflict with this (Events, Google Analytics, Google Sitemaps, Askimet). I’m using the WP Framework theme that I customized for design and not much more.

    My pages are pulling the .css & .js files into the head and my source code structure looks almost the same as this form. I click submit on an empty form and get the WP default page….

    What am I missing??

  22. 15. April 2009 |20:02

    @Dappy: It looks like jQuery is loaded twice on your site, once elsewhere and once by the comment validation plugin. Try to remove one of the includes.

  23. 16. April 2009 |00:57

    I finally got it to work. You might want to add to your description:
    The form tag MUST have an id of #commentform or else it won’t work even if the commentvalidation.js and .css files are edited.

    Mine was #comment-form to follow my coding method and the syntax WP Framework had been using. I actually think WP framework made that change.

    - Thanks, Dappy

  24. Ed
    2. July 2009 |12:50

    Is there a way to customise the error message:

    >> Please enter a valid email address.

    and also add a “Please enter you name” one

  25. 14. July 2009 |18:26

    dankeee

  26. 14. August 2009 |15:35

    Works fine on my 2.8.4, no admin screen though. Thanks

  27. 10. September 2009 |21:14

    I want the error messages to be displayed under the particular input element, i.e. if the error is in email field then it just shows under email field only, so as to make it even better user experience.
    Any solutions for that?
    Thanks in advance…

  28. Bb
    15. September 2009 |23:49

    Seems to be a stray in the comment-validation.php file (/wp-content/plugins/comment-validation/comment-validation.css">). Other than that this works great.

  29. Bb
    15. September 2009 |23:51

    Stray </script> – got stripped out in my last comment.

  30. 28. September 2009 |05:39

    Very useful.

    Thanks a lot.

  31. Deno
    29. October 2009 |21:50

    I have to make a remark to that first comment on your page and am sorry! People need to be alittle more appreciative to people like you who help us the people learning. I more than well appreciate the time spent by others, so that I can grow and become better. If more people showed graditude instead of negativity, the world might be different. Thankyou for your time given to us.

  32. Ralph
    30. October 2009 |18:42

    Nice plugin, works great with my site. But since the JS files are packed, I can’t translate the error messages. Could you make this possible? Thanks!

  33. 1. November 2009 |09:18

    @Ed and Ralph: Take a look at the jQuery validation plugin (also on this site). Thats whats used by the WordPress plugin. You can customize messages, even without modifying the packed file, by overwriting some JavaScript variables in your own script, included after the other files.

    For example, to set a different message for a required field:

    $.validator.messages.required = "Please fill out this field";

    @iklan: There is no admin screen, yet.

  34. Ralph
    2. November 2009 |18:23

    Thanks, works perfect!

    For the people who also want to translate the error messages:

    Open the comment-validation.js file:

    Translate the error message at the 2nd line (between the DIVs).

    And find:

    $.validator.messages.email = “» ” + $.validator.messages.email;
    $.validator.messages.url = “» ” + $.validator.messages.url;

    And translate as follows:

    $.validator.messages.email = “» EMAIL ERROR IN YOUR LANGUAGE”;
    $.validator.messages.url = “» URL ERROR IN YOUR LANGUAGE”;

    That’s it! Thanks again!

  35. Ralph
    2. November 2009 |20:36

    I’ve got 1 question remaining:

    Is it possible to get the plugin to validate extra comment form fields?

    I’m asking this because I’ve some radio buttons, which should be required when filling in the comment form.

  36. 2. November 2009 |21:55

    @Ralph: You can add that in the comment-validation.js file, too. Just specify additional rules. Details can be found in the Validation Plugin documentation.

  37. Ralph
    3. November 2009 |04:38

    Thanks for the quick reply, Jörn!

    I’m sorry for not explaining myself properly right from the start. The thing is that adding an extra rule does indeed validate a normal radio button.

    At first I didn’t think this wasn’t the case, but after your advise I looked at it again and found out that it did work. The problem is that I want to validate jQuery Star Rating Plugin:

    http://www.fyneworks.com/jquery/star-rating/#tab-Overview

    This plugin turns radio buttons into stars. Despite the fact that the radio buttons are still in the source, the validator ignores them as soon as they’re being displayed as stars.

    Do you think this can be solved somehow?

  38. Ralph
    4. November 2009 |20:04

    I solved the problem of the star rater not being validated as follows:

    The value of the star rater is now being passed to a hidded field in the form.

    Validator plugin then validates the hidden field.

    Works perfect! Thanks again!

  39. 2. January 2010 |14:32

    works perfect

  40. 3. January 2010 |09:19

    This plugin is loading Javascript incorrectly. You need to use the built in wp_enqueue_script functions, because loading jQuery separately can mess up JavaScript loaded by other plugins.

  41. 4. January 2010 |18:37

    @Dan: Thanks for the info. I’ll look into it.

  42. 7. January 2010 |02:03

    After installing this plugin and activating it, it broke the Lightroom 2 plugin.

    The Lightroom 2 plugin no longer works at all.

    When an image is clicked on, it goes to the image URL instead of opening it with Lightroom 2.

  43. billy
    7. January 2010 |22:05

    Great plugin!!
    to John Gohde: please shut the fuck up! and respect the architect!!!!!
    You have to be pleased that some people can even try to speak english. ’cause i’m sure that without english you belong to the Trash.

  44. 12. January 2010 |16:18

    Seems to be a problem when validating the URL field.

    http://www.google.com — FAILS
    google.com — FAILS
    http://google.com — WINS
    http://www.google.com — WINS

    This could be a problem for users when entering their URL. Any chance you can take a look and maybe offer up an updated file?

    Cheers,
    Dave

    svenja Reply:

    Hi,

    is there a solution for this bug?
    I got the same problem.
    Thanks a lot.

    Bye,
    Svenja

  45. 18. January 2010 |22:20

    you have a big error in comment-validation.php on line 15

    echo ‘/wp-content/plugins/comment-validation/comment-validation.css”>’;

    should be

    echo ‘/wp-content/plugins/comment-validation/comment-validation.css” />’;

    since you are closing the link tag, not a script one.

  46. Tony Boyce
    24. January 2010 |12:51

    Thanks for this. I’m building a site using 2.9.1 from the ground up and it worked for me. Saved me a lot of work but could not get it to validate. Following info from the validation site I was guided to this piece of code in the comment-validation.php.

    echo ”;

    The closing tag ‘script’ should not be there. I removed it and closed the ‘link’ tag and it validates fine.
    It now looks like this:

    echo ”;

    Thanks again

  47. Tony Boyce
    24. January 2010 |12:55

    Sorry, new to this and didn’t know that I couldn’t post code. The extra ‘script’ tag came after

    comment-validation.css

  48. David
    27. March 2010 |21:03

    this is perfect. FINALLY a plugin that worked for me. thank you very much.

  49. tobi
    7. April 2010 |09:36

    hi jörn,

    i use the plugin wp-e-commerce and as soon as i activate your plugin the lightbox effect on my productpage (images) does not work anymore. when you click on an image it goes to the image url…
    is there a way to fix it?

  50. 25. November 2011 |00:43

    Thanks for the plugin! I´ve finally found it.
    Thats what i was looking for.

    Kind regards!!

  51. 10. February 2012 |01:03

    I just want to thank you so much for this plugin! It is so simple yet so functional. I had it up and running and lightly customized in less than two minutes. Many, many thanks!

  52. daneyal
    25. February 2012 |00:24

    Thanks for this plugin.

  53. Mike
    10. April 2012 |22:58

    It would be great to have this type of functionality for the WordPress signup form. Any chance of a plugin for that? Or some direction on how to proceed based on your work on the Comment Validation plugin?

    Thanks!

  54. 11. April 2012 |11:28

    @Mike: Take a look at the source for this plugin, its pretty simple. That should be a good starting point.

  55. g
    13. June 2012 |06:58

    I like this, it’s very useful.

    Can it be made to handle errors in a way more similar to the jQuery Validation Plugin Demo – where text is placed below the appropriate field(s)?

  56. 22. August 2012 |04:35

    Well .. Thankx a ton for this great plugin , it will really help in preventing the hundreds of SPAM comments on our WP blogs. it is really helpful..
    Thanks again..!!!…

  57. 3. September 2012 |04:16

    I was in a severe need of such plugin now i will use it in my blog. I hope it will really help me to control the unwanted comments. Thanks a lot…