Form validation - Always false? |
I have a very basic form with a controller that looks like this:
class Home extends BaseController PHP Code: { The view has a section at the top for showing the errors: PHP Code: <?php if($validation->listErrors()) {?> For some reason the validation is always triggered and I can't figure out why. Should you use seperate functions in CI4?
The user guide is a little vague or maybe even incorrect. If I follow the tutorial on:
https://codeigniter.com/user_guide/libra...n-tutorial I get the same error as you get.
I will post here an example from my Register page. I hope it will also work for you.
Controller: PHP Code: $data = [ In your Register page PHP Code: <?php if(isset($validation)){ (07-25-2022, 10:05 PM)vinyl Wrote: Thanks, wil give that a try today! No need for this. Believe me there are lots of tutorials now, both on blogs or on YouTube. You will handle it easily. CI4 is nice enough. P.S. Maybe you should paste more code examples here.. eg: your view, controller, results etc. (07-25-2022, 05:56 AM)JustJohnQ Wrote: The user guide is a little vague or maybe even incorrect. If I follow the tutorial on: What error do you get?
Sorry, I should have been more clear. I did not get an error, just unexpected results. While loading the page for the first time it shows the validation errors straight away.
It looks like the manual is missing some additional code to check for a POST request before displaying any validation errors. (07-26-2022, 12:28 PM)JustJohnQ Wrote: While loading the page for the first time it shows the validation errors straight away. Indeed, it is a bit odd to see validation errors for the first time. I sent a PR to improve the tutorial code: https://github.com/codeigniter4/CodeIgniter4/pull/6300
@JustJohnQ
Form Validation Tutorial has been updated: https://codeigniter4.github.io/CodeIgnit...n-tutorial |
Welcome Guest, Not a member yet? Register Sign In |