Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

islowercase validator not working (solved) #251

Open
patrickatwsrn opened this issue May 23, 2021 · 0 comments
Open

islowercase validator not working (solved) #251

patrickatwsrn opened this issue May 23, 2021 · 0 comments

Comments

@patrickatwsrn
Copy link

patrickatwsrn commented May 23, 2021

Before you read this...

The problem was caused because I have a habit of putting commas in front of the following line:

[[!FormIt?
   &validate=`
         lowercasetext:required:islowercase
         ,name:required`
]]

This breaks the validation.

[[!FormIt?
   &validate=`
         lowercasetext:required:islowercase,
         name:required`
]]

This works.

In a similar bug report reported by me the issue was caused by the same problem.

Bug report

Summary

islowercase always seems to return true, regardless of validated content.

Step to reproduce

[[!FormIt?
   &validate=`
         someDate:required:isDate==^%Y-%m-%d^
        ,lowercasetext:required:islowercase
        ,name:required`
]]

[[!FormIt?
   &validate=`
         lowercasetext:required:islowercase
        ,name:required`
]]

<form action="[[++site_url]][[~[[*id]]]]" method="post">
    <div>
        <label> Name<br>
            <input type="text" name="name" value="[[!+fi.name]]" />
        </label>
        [[!+fi.error.name]]
    </div>
    
    <div>
        <label>islowercase<br>
            <input type="text" name="lowercasetext" value="[[!+fi.lowercasetext]]" />
        </label>
        [[!+fi.error.lowercasetext]]
    </div>

    <hr>

    <button type="submit" name="submit" value="test">Send</button>
</form>

Observed behavior

Insert string "lower"

grafik

After submiting the form:
grafik

Insert string "LOWER"

grafik

After submiting the form:
grafik

  • "name" is marked as an error because it is required

  • "islowercase" is not marked even though it containes uppercase letters. BAD

  • "name" is marked as an error because it is required

  • "islowercase" is not marked because containes uppercase letters. GOOD

It doesn't matter what goes into the lowercasetext. The validator never returns an error. BAD

Possible Problems

This does not seem to be related to the lexicon file, because there is a string for this error:

  • formit.not_lowercase - en: This field must be all lowercase.
  • formit.not_lowercase - de: Dieses Feld bitte nur in Kleinbuchstaben ausfüllen.

Ths issue should be located in validator.php, but to be honest I can't see what could ever go wrong here:

core/components/formit/src/FormIt/Validator.php, LINE # 678

    /**
     * Checks to see if a string is all lowercase
     * @param string $key The name of the field
     * @param string $value The value of the field
     * @return boolean
     */
    public function islowercase($key, $value)
    {
        $v = $this->config['use_multibyte'] ? mb_strtolower($value,$this->config['encoding']) : strtolower($value);
        return strcmp($v, $value) == 0 ? true : $this->_getErrorMessage($key,'vTextIsLowerCase','formit.not_lowercase',array(
            'field' => $key,
            'value' => $value,
        ));
    }

According to my phpinfo page "Multibyte decoding support using mbstring" is enabled and the setting for "use_multibyte" is true. Comparing the original value with the strtolower or mb_strtolower.

Question: What is $this->config['encoding'] supposed to return? It is not a setting that can be displayed on the settings page. Neither core nor formit have this variable.

Expected behavior

"LOWER" should return an error. BAD
"lower" should not return an error. FINE

Environment

MODX 2.8.1, Formit 4.2.6 , PHP 7.4.18, Apache Webserver Running on Ubuntu Linux.

@patrickatwsrn patrickatwsrn changed the title islowercase validator not working islowercase validator not working (solved) May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant