• Resolved deepsikder

    (@deepsikder)


    Hi,
    I want to have a support from you regarding the word lengths while writing in the review field. I want to put a maximum and minimum word (or character) count rule in the review form. Also, display the no. of words/characters left in the review field. How to achieve that?

    Note: I found the max character lengths in the faq section but without character alarm.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    1. Using the example in the FAQ, you can add a minimum value like this:

    To ‘site-reviews/config/forms/submission-form’ add this:
    $config['content']['minlength'] = 20;

    and to ‘site-reviews/validation/rules’ change to this:

    $rules['content'] = 'required|max:100|min:20';

    2. You would have to add this yourself as it is not a feature of Site Reviews and it would require some third-party javascript to do. For example: https://sacha.me/Countable/

    Thread Starter deepsikder

    (@deepsikder)

    Thanks for your support.
    But can we display a warning as soon as it reaches 100 characters (as it is showing in minimum character length). See the screenshot https://prntscr.com/usexby

    Plugin Author Gemini Labs

    (@geminilabs)

    The javascript validation that Site Reviews uses is an extremely light layer sprinkled on top of the native HTML5 validation. Meaning, it uses the existing HTML5 attributes of the tag to determine whether it is valid or not.

    The maxlength is a <textarea> attribute used in HTML5 validation that restricts the textarea to a specified number of characters. If this attribute is present, the textarea will be restricted to (you will not be able to type more than) the specified number of characters.

    If you would prefer to not use the HTML5 attributes for validation, you will have to wait for Site Reviews v5.0 which allows you to simulate the attributes without the restrictions using data-* attributes.

    For example:

    add_filter('site-reviews/config/forms/review-form', function ($config) {
        if (array_key_exists('content', $config)) {
            $config['content']['data-minlength'] = 10;
            $config['content']['data-maxlength'] = 100;
        }
        return $config;
    });
    

    If you cannot wait for the official release, you can download the unreleased development version here: https://github.com/pryley/site-reviews/archive/develop.zip

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Validation with word/character length’ is closed to new replies.