CodeIgniter Forums
Form Re-submission Error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Form Re-submission Error (/thread-79007.html)



Form Re-submission Error - waleed - 04-07-2021

Hye guys.
Just need a help!!!
When I was using ci3 so I faced an issue when user clicked browser back button, that's show " resubmit the form", so I solved that issue after setting header in ci3. Now I upgrade my site ci3 to ci4 and again I m facing same issue. Can anyone plz convert this code in CI4?


CI 3 code in Controller construct


$this->output->set_header('Last-Modified:' . gmdate('D, d M Y H:i[Image: confused.png]') . 'GMT');
$this->output->set_header('Cache-Control: no-cache, must-revalidate');
$this->output->set_header('Cache-Control: post-check=0, pre-check=0', false);
$this->output->set_header('Pragma: no-cache');

CI 4 code in BaseController

$response->setHeader('Last-Modified',gmdate("D, d M Y H:i[Image: confused.png]").'GMT');
$response->setHeader('Cache-Control', 'no-store');
$response->setHeader('Cache-Control', 'no-cache');
$response->setHeader('Cache-Control', 'must-revalidate');
$response->setHeader('Cache-Control', 'post-check=0');
$response->setHeader('Cache-Control', 'pre-check=0');
$response->setHeader('Pragma','no-cache');
$response->setHeader('Cache-Control', 'no-cache');

In CI 4 it is not working.
Any help will be appreciated.


RE: Form Re-submission Error - InsiteFX - 04-07-2021

You could try this and the end of your code/

PHP Code:
// Sends the output to the browser
// This is typically handled by the framework
$response->send(); 



RE: Form Re-submission Error - waleed - 04-07-2021

Thanks for you reply..

I have already checked this but not works.


RE: Form Re-submission Error - umarbhatti58 - 04-08-2021

I was facing same issue and didn't find any authentic solution using ci4.
main difference which i saw was in ci3 while setting header there is set-cookie index in header array but in ci4 cookie did not set by setting header.
I hope someone also was facing that one.


RE: Form Re-submission Error - InsiteFX - 04-08-2021

This article may help you figure it out.

How to prevent form resubmission when page is refreshed (F5 / CTRL+R)


RE: Form Re-submission Error - waleed - 04-15-2021

I found the solution by using the following code.
Paste the code in Base controller

$response->removeHeader('Cache-Control');


header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");

Firstly remove the all build-in headers than add new ones.