Reputation: 4568
I know the preferred way to prevent the 'confirm form resubmission' warning is to use GET. But when using Codeigniter you're mostly steered towards using POST (in the sense that most of the form helper functions won't work and other things).
What's the best way to prevent 'Confirm Form Resubmission' warning when using Codeigniter?
EDIT: people have good ideas, but my issue is that this is a search page where I want the form to be resubmitted. I can't use a redirect because that will wipe out the POST data.
Upvotes: 1
Views: 5583
Reputation: 586
For codeigniter. use
$post_data = $this->session->userdata('post_data');
if ($post_data == $_POST){
$this->session->unset_userdata('post_data');
redirect(current_url(), 'refresh');
}else{
$this->session->set_userdata('post_data', $_POST );
}
And for php, use
$post_data = $_SESSION['post_data'] ?? null;
if ($post_data == $_POST){
unset($_SESSION['post_data']);
redirect(current_url(), 'refresh');
}else{
$this->session->set_userdata('post_data', $_POST );
}
Upvotes: 0
Reputation: 363
Suhindra is correct.
I used that pattern when I created my blog engine. The controller method that processes blog post input, for example, ends with this code--a redirect to where a page is loaded, rather than a direct page load:
$this->session->set_flashdata('info', 'blog post created');
$this->load->helper('url');
redirect("/blogs/$posts_id", "refresh");
Upvotes: 1
Reputation: 111
Clear cache after sending the request
$this->output->set_header('HTTP/1.0 200 OK');
$this->output->set_header('HTTP/1.1 200 OK');
$this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
$this->output->set_header('Cache-Control: post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
$this->load->view('header', $data);
$this->load->view('nav', $data);
$this->load->view('searchdesigns', $data);
$this->load->view('footer', $data);
Upvotes: 0
Reputation: 314
USE redirect("./conrtollerName/SETTING/","refresh");
instead of $this->load->view('SETTING');
Upvotes: 0
Reputation: 810
You can unset value of form after success and work done.check my answer and i was having same issue :
Clear form data after success codeigniter using php not jquery
Upvotes: 0
Reputation: 355
Try redirect to itself in controller, redirection will server the job as next time it will not get the form for submitting,
Upvotes: 1