1. Osclass Forum
  2. Ideas/Improvements
  3. How to Require A Minimum Description Character Count in Oscl...

How to Require A Minimum Description Character Count in Osclass

Started by Matt, January 27, 2024, 9:34 pm

  • 1

Matt

I know we can control the max characters used in the description but how can one require a minimum character count for the description? Sometimes people just put  a few words and it does not look very good. I would like to require a description of at least 1000 characters.


Thank you.

calinbehtuk

In your theme functions.php or index.php from an active plugin add the next code

Code: [Select]
​function cbk_min_description_text($flash_error, $item) {
    $minValue = 1000;
    if (isset($item['description'])) {
        $error = '';
        foreach ($item['description'] as $key => $value) {
            $count = strlen($value);
            if ($count < $minValue) {
                $error = sprintf(_m('Description too short (%s).'), $minValue);
                break;
            }
        }
    }


    $flash_error .= $error;
    return $flash_error;
}

osc_add_filter('pre_item_add_error', 'cbk_min_description_text');


$minValue = 1000; here you change the minimum characters

Matt

Thank you! I will try that out and report back.

Matt

I put this in functions.php and it worked perfectly! Thank you!

  • 1
Subscribe
X

Subscribe!

Subscribe to get the latest listings, updates and special offers delivered directly in your inbox.