Validation div always appears in view even if empty |
Hi,
I'm quite new to CodeIgniter and website development in general. I'm following various tutorials and examples as well the official documentation, however I'm having some difficulties with displaying validation errors in my view. Here's my controller section related to validation of a form input: PHP Code: public function add() and here's my view where I want to show validation errors if they happen: PHP Code: <?php $validation = \Config\Services::validation(); ?> in this case the result is that whenever I reach the view (even if post action has not been sent) I see the "alert div" block obviously empty of content. Of course I want it to be empty in that case. If I remove the line PHP Code: <?php $validation = \Config\Services::validation(); ?> PHP Code: withInput()->with('validation', $this->validator) Any suggestion? What's the best practice to have the validation errors shown as I want to? Thanks in advance
Try:
PHP Code: ->with('errors', $this->validator->listErrors()) And in the view: PHP Code: <?php $errors = session()->getFlashdata('errors'); ?> |
Welcome Guest, Not a member yet? Register Sign In |