Welcome Guest, Not a member yet? Register   Sign In
Call to a member function on bool
#1

I'm stuck on validation.
the "validate" instance does not recognize the "hasError" functions:
returning the error:
Call to a member function hasError () on bool

PHP Code:
$validation $this->validate([
            
'user'    =>'required',
//            'mail'    =>'required|valid_email|is_unique[users.mail]',
            
'mail'    =>'required|valid_email',
            
'pswd'     =>'required|min_length[5]|max_length[12]',
            
'cPswd'    =>'required|min_length[5]|max_length[12]|matches[password]'
        
]);


        if(!
$validation){
        
$usrErr $validation->hasError('user') ? $validation->getError('user') : "";
            echo 
'user: '.$usrErr;                
        }else{
            echo 
"corretto";    

        } 

after seeing and reviewing several tutorials on the subject, I am at a standstill.

I hope to get help from the experts
Reply
#2

(This post was last modified: 05-02-2021, 03:38 PM by includebeer.)

If you are calling this from a controller, you need to call the getError function like this:
PHP Code:
if(!$validation){
        $usrErr $this->validator->hasError('user') ? $this->validator->getError('user') : "";
            echo 'user: '.$usrErr;                


In your code, $validation is the result of the validation you just made. It's not an instance of the validation library.

See the "Validation data" section in the user guide: http://codeigniter.com/user_guide/incomi...ating-data
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

(05-02-2021, 03:36 PM)includebeer Wrote: If you are calling this from a controller, you need to call the getError function like this:
PHP Code:
if(!$validation){
        $usrErr $this->validator->hasError('user') ? $this->validator->getError('user') : "";
            echo 'user: '.$usrErr;                


In your code, $validation is the result of the validation you just made. It's not an instance of the validation library.

See the "Validation data" section in the user guide: http://codeigniter.com/user_guide/incomi...ating-data
Thank you so much, you're great! I've been stuck on this for a long time.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB