Welcome Guest, Not a member yet? Register   Sign In
To avoid seeing "confirmation of form submission" box...
#1

[eluser]veledrom[/eluser]
Hi,

To avoid seeing "confirmation of form submission" box when we use F5 or Back button on browser after form submission, what should I do? It should also enable me to use "form validation" helper and "set_values" functionality for input areas in the form.

Like how they do on this forum. When we login, we never see that annoying "confirmation of form submission" box when we use F5 or Back button on browser.

Thanks
#2

[eluser]Clooner[/eluser]
Because after the form submission there is a redirect!
#3

[eluser]veledrom[/eluser]
If I use redirect(), I cannot display validation_errors() and set_value() in actual page if validation fails.
#4

[eluser]CroNiX[/eluser]
Send no cache headers on the page with the form. Then it won't get cached.

Here's a helper function I use:
Code:
function send_no_cache_headers()
{
  //no cache
  header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  header("Pragma: no-cache");
  header('Expires: ' . gmdate(DATE_RFC1123, time()-1));
}

As far as the redirect issue, you could store the validation errors in session.
#5

[eluser]veledrom[/eluser]
Thanks I'll try it tomorrow.
#6

[eluser]veledrom[/eluser]
After successful login, If I go back and forward, I don't see the login form page nor submission confirmation popup. That's fine. However, if I fail to login and, go back and try to go forward again, I'm asked to confirm submission again. Do I miss anything below?

Thnaks


LOGIN FORM

Code:
<div id="div_box">
&lt;?php echo form_open('login/do_login', array('name' => 'login', 'onsubmit' => 'return login_hash()')); ?&gt;

Username : &lt;input type="text" name="text_username" value="&lt;?php echo set_value('text_username'); ?&gt;" /&gt;
<br /><br />
Password : &lt;input type="password" name="text_password" value="" /&gt;
<br /><br /><br />
&lt;input type="hidden" name="hidden_form_hash" value="&lt;?php echo $form_hash; ?&gt;" /&gt;
&lt;input type="submit" name="submit_button" value="Login" /&gt;

&lt;?php echo '&lt;/form&gt;'; ?&gt;
</div>

CONTENT OF login CLASS

Code:
public function stop_caching()
{
   $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
   $this->output->set_header('Pragma: no-cache');
}

public function index()
{
   $this->stop_caching();
  
   $this->load->helper('form');
   $data['page'] = 'login/index_view';
   $this->load->view('template', $data);
}

public function do_login()
{
   if ($this->input->post('submit_button') != 'Login') { redirect(); }
  
   $this->load->library('form_validation');
  
   //.......
   //.......
   //.......
  
   if ($this->form_validation->run() === true)
   {
      $this->session->set_userdata('user_data', $user_data);
      redirect();
   }
   else
   {
      $this->validation_errors[] = validation_errors();
      $this->index();
   }
}


#7

[eluser]veledrom[/eluser]
Problem solved in http://ellislab.com/forums/viewthread/217176/




Theme © iAndrew 2016 - Forum software by © MyBB