Forum Moderators: coopster

Message Too Old, No Replies

forcing a hard "reload this page" on a form

having trouble changing a screen

         

richb201

8:14 pm on Jul 13, 2021 (gmt 0)



I have a report that gets displayed for the last year that a specific user displayed. I am saving this in mysql for each user. I also save it in a session variable. Inside that report I have pull down control where the user can chose a different year for the report and then press submit. Here is the code for the submit:

<form method="post">

<?php
$taxyear=$_SESSION['last_TY'];
\koolreport\inputs\Select::create(array(
"name"=>"taxyear",
"data"=>$_SESSION['TY'],
"defaultOption"=>array($taxyear=>$_SESSION['last_TY']),
));
?>
<button type="submit"><< change tax year</button>
</form>



The user can pick the new year without an issue. When they press submit, the report doesn't change UNLESS they press F5. When they do this, a browser "resubmission" popup appears. When they click "continue", the report then displays correctly.

The pulldown is on the report page itself.

So I need to be able to force a form resubmission somehow. How can I do this?

dstiles

10:08 am on Jul 14, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have no problem resubmitting forms but have you set the page expiry metas correctly? I do this in two places. It's controlled by a var so that ordinary pages have a log expiry time and others such as forms are immediate.

Before the doctype...
if ($ExpireIt) {
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
}
else {
header('Cache-Control: public, must-revalidate, max-age=86400,no-transform'); // 24 hours in seconds
header('Expires: 1440'); // 24 hours in minutes
}


In the HTML header section...
if ($ExpireIt) {
echo "<meta http-equiv=\"expires\" content=\"0\">\n" .
"<meta http-equiv=\"pragma\" content=\"no-cache\">\n" .
"<meta http-equiv=\"cache-control\" content=\"no-cache\">\n";
}

richb201

10:52 am on Jul 14, 2021 (gmt 0)



Thanks Mr dstiles. My application is "all forms". Actually it is many, many pages of a CRUD, and then a report. It is the report that has a form embedded in it. I don't have a single page that stays the same for a while (except perhaps the dashboard). I like your method. Can I do this to the entire site by sticking in the site template?

richb201

11:13 am on Jul 14, 2021 (gmt 0)



BTW, the initial problem I had I managed to solve by using

<?php
if (isset($_POST['taxyear'])) {
$_SESSION['last_TY'] = $_POST['taxyear'];//update the laST YEAR
header("Refresh:0"); <<<<<this line
}
?>

Now when a user presses submit, the screen blinks twice and the report repaints!

dstiles

9:09 am on Jul 15, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



> Can I do this to the entire site by sticking in the site template?

My sites each have a common header/tail file that's included in every page. That code comes from that header. All you have to do to put it into a common header file is to define $ExpireIt in each page - or, as I do, make the default initialization in the header file to be false and then you only need to change the value to true in thos pages that need to expire quickly.