Symfony form validation issue

I can’t understand what I can do wrong with the next validation of the Symfony 1.4 form. Basically, all I just want is to consider all four conditions (required, minimum length, maximum length, regular expression). It actually WORKS, but for the “mandatory” condition, it does not display my custom error message and instead simply says “Required”. Is there a way to get a MY error message?

'username' => new sfValidatorAnd(array(
    new sfValidatorString(
        array('required' => true, 'min_length' => 4, 'max_length' => 20), 
        array('required' => 'Please enter a username.', 'min_length' => 'Your username must have at least 4 characters.', 'max_length' => 'Your username cannot be longer than 20 characters.')
        ),
    new sfValidatorRegex(
        array('pattern' => '/^[A-z0-9]*$/i'),
        array('invalid' => 'Your username can only have letters (A-Z) or numbers (0-9).')
        ),
)),

One more thing, if I remove the Regex validator and just turn it into a regular one-line check String, my custom error message shows !?

Is anyone

Thanks in advance.

+3
1

- sfValidatorAnd :

'username' => new sfValidatorAnd(array(
    new sfValidatorString(
        array('required' => true, 'min_length' => 4, 'max_length' => 20), 
        array( 'min_length' => 'Your username must have at least 4 characters.', 'max_length' => 'Your username cannot be longer than 20 characters.')
        ),
    new sfValidatorRegex(
        array('pattern' => '/^[A-z0-9]*$/i'),
        array('invalid' => 'Your username can only have letters (A-Z) or numbers (0-9).')
        ),
), array(), array('required' => 'Please enter a username.')),

, , .

+6

Source: https://habr.com/ru/post/1729669/


All Articles