Validation doesn't work |
Like in the thread subject, I have an issue where if the first field is empty and then I click the submit button, it should show "is-invalid" class from bootstrap. But, I don't know why but in my case, "is-invalid" doesn't appear. To reconstruct it is in the video below, and the code is in the link provided. I'm using CodeIgniter v4.4.5
Code: Comic.php: https://srcb.in/WpK36Jtntv create.php: https://srcb.in/2bQAvdBdeG BaseController.php: https://srcb.in/SzAbQ0mhtm Routes.php: https://srcb.in/7xD5kTzVqt Video tutorial + what I expected to be: https://youtu.be/IfMWgZf-To0?t=773 Video: [Video: https://youtu.be/CshKImwRrcI]
When the field is empty (invalid), you redirect to "/comic/create".
That is the browser send another request to the server. So the $validation in the view is not the same instance as the Validation instance in the first request. You saved the Validation instance into the flash message in the session. You need to get it from the session. See https://codeigniter4.github.io/CodeIgnit...ion-errors
If your validation fail and you want to return view with errors it will be better to use
PHP Code: // Controller: (02-27-2024, 09:25 PM)kenjis Wrote: When the field is empty (invalid), you redirect to "/comic/create". Thank you! This one is work for me as well, I don't know if it's the good or the perfect one but at least, I've tried to find the code by myself and proud of myself because I can figure it out. PHP Code: <?= session()->getFlashdata('validation') ? 'is-invalid' : ''; ?> |
Welcome Guest, Not a member yet? Register Sign In |