Welcome Guest, Not a member yet? Register   Sign In
Form reload - post array is empty
#3

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");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");


This will prevent browser caching and will keep the data on post requests.
Reply


Messages In This Thread
Form reload - post array is empty - by groovebird - 01-24-2023, 10:00 AM
RE: Form reload - post array is empty - by kenjis - 01-24-2023, 05:10 PM
RE: Form reload - post array is empty - by yaju - 01-24-2023, 11:08 PM



Theme © iAndrew 2016 - Forum software by © MyBB