We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

StringLength Validator [SOLVED]

Hi, i have some problem with StrLength validator:

$password = new Password('password', array('required' => true, 'class' => 'span12'));
        $password->addValidators(array(
            new PresenceOf(array(
                'message' => 'password required',
            )),
            new StringLength(array(
                'min' => 8,
                'messageMinimum' => 'Password is too short. Minimum 8 characters'
            )),
            new Confirmation(array(
                'message' => 'Password doesn\'t match confirmation',
                'with' => 'repassword'
            ))
        ));

And i got error:

#0  Phalcon\Mvc\Model\Validator\StringLength->validate(Object(Phalcon\Validation), password)
#1  Phalcon\Validation->validate(Array([id] => (empty string), [csrf] => a7ee72dcd676d63f5937876b2f6485c5, [login] => login, [name] => full name, [email] => [email protected], [role] => member, [password] => pass, [repassword] => pass), null)
#2  Phalcon\Forms\Form->isValid(Array([id] => (empty string), [csrf] => a7ee72dcd676d63f5937876b2f6485c5, [login] => login, [name] => full name, [email] => [email protected], [role] => member, [password] => pass, [repassword] => pass))

Controller:

        if($request->isPost()){
            if($userForm->isValid($this->request->getPost())){
               //....
            }
        }


98.9k

Can you please print the message generated by the exception?

catch (Exception $e) {
  echo $e->getMessage();
  echo $e->getTraceAsString();
}


11.8k
( ! ) Fatal error: Uncaught exception 'BadMethodCallException' with message 'Wrong number of parameters' in C:\wamp\www\phalcon\app\modules\User\Controller\UserController.php on line 31
( ! ) BadMethodCallException: Wrong number of parameters in C:\wamp\www\phalcon\app\modules\User\Controller\UserController.php on line 31

line 31 Phalcon\Forms\Form->isValid( )

P.S. When i delete this validator validation was good



98.9k

This is your code: https://gist.github.com/phalcon/5961217 it's running here: https://test.phalcon.io/form.php

Please let me know what change to see the exception



11.8k

Thx Phalcon. Problem was because I use

Phalcon\Mvc\Model\Validator\StringLength

not a

Phalcon\Validation\Validator\StringLength