• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to display form validation error on view page?

#1
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 $[b]validation->getError('username');[/b]

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 ?
Reply

#2
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 )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.