1

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.

dmgig
  • 4,400
  • 5
  • 36
  • 47
  • [Already answered here?](http://stackoverflow.com/questions/6833914/how-to-prevent-the-confirm-form-resubmission-dialog) – ourmandave Mar 01 '17 at 23:56
  • I saw that one, but my basic problem is I want the user to be able to resubmit their data. This is a search function, and if they move back, they should be able to see their old searches. I should have made that clear, sorry about that. – dmgig Mar 02 '17 at 16:43

6 Answers6

1

Try redirect to itself in controller, redirection will server the job as next time it will not get the form for submitting,

Suhindra
  • 355
  • 2
  • 10
  • Right, but this is for a "search" function (I should have made that clear) where I need the user input to be present in the new view. A redirect will wipe out the users inputs – dmgig Mar 02 '17 at 16:41
1

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");
Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
pacificpelican
  • 363
  • 1
  • 7
  • Right, but this is for a "search" function (I should have made that clear) where I need the user input to be present in the new display. A redirect will throw out their info (unless I put it into a session, but that seems... I'm not sure that seems right). – dmgig Mar 02 '17 at 16:40
0

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

Bhunesh Satpada
  • 770
  • 1
  • 6
  • 19
0

USE redirect("./conrtollerName/SETTING/","refresh"); instead of $this->load->view('SETTING');

Alien
  • 15,141
  • 6
  • 37
  • 57
Devang Hire
  • 174
  • 1
  • 5
0

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);
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
0

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 );
}
Ellix4u
  • 566
  • 5
  • 9