Form reload - post array is empty |
Hi,
if the form was submitted and i reload the form then i get the message that all post data are sent again. this is the normal behaviour. If i reload the form again, then codeigniter redirects to the same url with a get request and all post data are gone. how can i prevent this redirect and why does it happen after a second reload?
It may be CSRF protection.
See https://codeigniter4.github.io/CodeIgnit...on-failure
This behavior is caused by the browser's caching mechanism. When a form is submitted, the browser stores the request method (POST) and the URL in its cache. When the user reloads the page, the browser uses the cached information to resubmit the form using the same request method (POST) and URL. However, when the user reloads the page again, the browser uses the cached information to resubmit the form using the GET request method instead of POST, and the POST data is lost.
To prevent this redirect, you can use the "POST-Redirect-GET" pattern. This involves redirecting the user to a different URL after the form is submitted, instead of reloading the same page. This way, when the user reloads the page, the browser makes a GET request to the new URL, and the POST data is not lost. You can also add this code in the controller Code: header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); |
Welcome Guest, Not a member yet? Register Sign In |