form submit with csrf not working |
(11-16-2021, 10:50 PM)coderscvoen Wrote: When i submit the form; i do not get any feedback from the flash messages have set. I'm not sure if I understand correctly, but if the CSRF validation fail, it will automatically set an "error" flash message and redirect to the previous page. So your view should echo the error variable if present: https://codeigniter.com/user_guide/libra...on-failure Quote:When a request fails the CSRF validation check, it will redirect to the previous page by default, setting an error flash message that you can display to the end user. (11-17-2021, 02:59 AM)captain-sensible Wrote: <?=form_open('contact') ?> You said it yourself, open_form() already add the CSRF field in your form. You don't need to add it again with csrf_field(). Maybe you like to do things your way, but then you'll break your site and waste time trying to understand why it doesn't work. If you don't trust the documentation, you can always look at the code to see what it really do: https://github.com/codeigniter4/CodeIgni...er.php#L62 PHP Code: // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites It is always a good idea to study the framework's code. Now you can see what is happening and you can learn some interesting things. Like here, I didn't know it doesn't add the csrf field if it's a GET method instead of a POST!
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ |
Messages In This Thread |
form submit with csrf not working - by coderscvoen - 11-16-2021, 10:50 PM
RE: form submit with csrf not working - by captain-sensible - 11-17-2021, 02:59 AM
RE: form submit with csrf not working - by coderscvoen - 11-17-2021, 06:33 PM
RE: form submit with csrf not working - by includebeer - 11-17-2021, 07:13 PM
RE: form submit with csrf not working - by simian100 - 11-18-2021, 09:07 AM
|