CodeIgniter Forums
Custom validation errors aren't showing but the default errors are - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Custom validation errors aren't showing but the default errors are (/showthread.php?tid=77348)



Custom validation errors aren't showing but the default errors are - Polymorphism - 08-20-2020

I'm trying to get the custom validation error messages to show up on my form.

I have defined the error messages inside the $validationMessage array of my model class 'Post' and it seems that the default ones are appearing.

I have even written stupid code like this to get it to work and they still don't
PHP Code:
    public function store()
    {
        $postModel = new Post();
        $rules $postModel->validationRules;
        $postModel->setValidationMessages($postModel->validationMessages);
        
        
if($this->request->getMethod() == 'post' && $this->validate($rules)) {

            $postModel->save([
                'title' => $this->request->getPost('title'),
                'content' => $this->request->getPost('content')
            ]);

        } else {
            $postModel->setValidationMessages($postModel->validationMessages);
            echo view('templates/header');
            echo view('posts/create-form', ['validator' => $this->validator ]);
            echo view('templates/footer');

        }
    

What am I doing wrong here?

Additionally (this could be another for another post) if I call:

PHP Code:
$postModel->errors() 

I get this error:

PHP Code:
Call to a member function lastErrorCode() on bool 

Why is this?