Codeigniter 4 form validation not working - something to do with action attribute |
I'm still getting to grips with Codeigniter 4 and I'm trying to overcome a form validation issue.
I keep hitting a brick wall with either losing `$_POST` data on submission, or reaching a 404 page does not exist error - and it all seems to centre on the `action` attribute of the form itself. My Controller code: Code: public function index() My SignUp Controller: Code: <html> When the form is submitted with `<?= site_url() ?>/form` as its action, validation fails because `$_POST` is empty. When the form is submitted with `<?= base_url() ?>/form` as its action, validation fails because `$_POST` is empty. When I use Codeigniter's form method `<?php echo form_open(); ?>`, validation fails because `$_POST` is empty. Same when I try `<?php echo form_open('form'); ?>` These are the only ways every article and YouTube video I've watched on the subject has done it - without any issue. When I change the code to this however... `<form action="" method="post">` - it WORKS! I am assuming this is only a fluke or a bug though. It's not really suitable though because if I try to reroute the same Controller, I get: Code: $routes->get('form', 'Form::index'); // works with action="" Could it just be a .htaccess issue? I have googled, but can't seem to find a clear answer.
Your route should use post method for form submission.
also it looks like form action is not defined PHP Code: $routes->post('...', '...'); get method is used for retrieving data from the server |
Welcome Guest, Not a member yet? Register Sign In |