Jump to content
Sign in to follow this  
jav100

Minimum / Maximum Number of Characters in Reviews

Recommended Posts

Hello, 

Is there an easy to to set the minimum / maximum number of characters for user reviews?

I checked the configuration page in the back-end menu but did not see an option for this (at least that's what my eyes are telling me!). 

I did see max number of characters for review comments.

A minimum number of characters in a user review will help increase the quality of user reviews and avoid reviews with just a few words ("this place is great". or "great")

Share this post


Link to post

This is one of those things that can be easily implemented with a developer filter. I added a new example to the documentation now to set a minimum required length for the review comments

<?php
defined('MVC_FRAMEWORK') or die;

function minimum_comment_length($validation, $params)
{
	$comment = S2Array::get($params,'data.Review.comments');

	$comment = strip_tags($comment);

	if ( strlen($comment) < 100 )
	{
		$validation[] = 'The review comment needs to be at least 100 characters';
	}

	return $validation;
}

Clickfwd\Hook\Filter::add('review_submit_validation', 'minimum_comment_length', 10);

And of course you can adjust that or extend it if you want to add a custom validation for any of the other review form submitted data.

Share this post


Link to post

I tried this but it did not work for me. 

I created an overrides folder in the path and file mentioned in the docs /templates/jreviews_overrides/filters/filter_functions.php

With the following text in the filter_functions.php file:

<?php
defined('MVC_FRAMEWORK') or die;

function minimum_comment_length($validation, $params)
{
    $comment = S2Array::get($params,'data.Review.comments');
 
    $comment = strip_tags($comment);
 
    if ( strlen($comment) < 100 )
    {
        $validation[] = 'The review comment needs to be at least 100 characters';
    }
 
    return $validation;
}
Clickfwd\Hook\Filter::add('review_submit_validation', 'minimum_comment_length', 10); 

I then realized that perhaps I needed to make the path and put the file within the template parent folder (/templates/ireview3/jreviews_overrides/filters), like below, but that did not work either. 

I tried clearing cache too but no luck. 

Can you let me know if I missed a step? 

Thanks

Share this post


Link to post

You used the correct path  /templates/jreviews_overrides/filters/filter_functions.php

I tested the code before posting it. Maybe try it once more and if it still doesn't work submit a ticket and I can take a look.

Share this post


Link to post
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Please refer to our Privacy Policy.