I have a Controller in Codeigniter like following :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Charity extends MY_Controller {
public function index()
{
if($this->input->method() === 'post'){
$data['name'] = $this->input->post('name');
$this->load->view('review_page', $data);
}else{
$this->load->view('charity');
}
}
}
the views are :
charity.php
<form method="post" action="/">
<input name="name" type="text"/>
<input value="send" type="submit"/>
</form>
review_page.php
<h1><?= echo $name; ?></h1>
When I submit the form I get the review_page view loaded but if I click on the browser's back button I come back to the form. Is there a why to make the form page expired after it is submitted so that the back button does not show it?
Thanks
Back button does not work because you never actually redirect to a different URL. You need to build your code so that it redirects. I would build another method that loads the review page like so
public function index() {
$this->load->view('charity');
}
public function reviews(){
if($this->input->method() === 'post'){
$data['name'] = $this->input->post('name');
$this->load->view('review_page', $data);
} else {
redirect('charity');
}
}
And your html
<form method="post" action="reviews">
Maybe this can help:
at the top of charity.php add this code:
<?php
session_start();
if ( isset($_SESSION['isSubmit']) and $_SESSION['isSubmit'] == 'ok' )
{
echo 'page is expired: form already submit !';
session_destroy();
}
?>
at the top of review_page.php add this code:
<?php
session_start();
$_SESSION['isSubmit'] = 'ok' ;
?>