Make comment form integrated ratings required

If you integrate ratings into comments form, it can be useful if you can make them mandatory. So, if the user doesn’t enter rating, form will not be submitted. To implement this, you need to add some JavaScript code that uses the plugin implemented functions to check this.

All my xScape themes support this by default, and all this is built into the framework. No custom work is needed if you decide to purchase any (or all) xScape themes, and all this will work out of the box, just needs to be activated using a option on the theme settings panel. xScape uses Validator in the comment form.

To do this, we need to prevent comment form from submitting. Then we check if rating is set, and if it is, form is submitted, if not alert message is displayed. This is very easy to do, and bellow you can see example jQuery JavaScript code to do this.

[code lang=”js”]jQuery(document).ready(function() {
jQuery("#commentform").submit(function(e) {
if (!is_cmm_rated_standard()) {
alert(‘Rating is required’);
return false;

On line 3 function in_cmm_rated_standard() is used. This is for standard rating block. If you integrate multi rating block, replace this function with is_cmm_rated_multis(). And that is all you need to do.

Note: This is not PHP code, this is JavaScript. It needs to go into some JavaScript file loaded by the theme, or added into template. I recommend adding it into the footer area.


Leave a Reply