Welcome Guest, Not a member yet? Register   Sign In
How to display form validation error on view page?

Hello friends!

In Codeigniter3 we can use helper function form_error() to display single error.
e.g: echo form_error('username');   // systax of CI3.

But in codeigniter4 we have to write like this:

// create object of validation.
$validation =  \Config\Services::validation();
echo [font=Consolas,]$[b]validation->getError('username');[/b][/font]

So its very tedious task (in CI4) to create object in every view page and then display single error.

Is there any helper function likes CI3 that we can use in CI4 ?

PHP Code:
// list all errors
<?= \Config\Services::validation()->listErrors(); ?>

// list defined error
$error = $validation->getError('username'); 

You also create custom error view files see the User Guide on validation library.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Theme © iAndrew 2016 - Forum software by © MyBB