Welcome Guest, Not a member yet? Register   Sign In
avoid sending data when refreshed page

how to avoid sending data into database when click on refresh button.
i already set validation.so no one can submit any empty feedback.but when a feed back is submitted and show the session message to the
user that feedback submitted successfully.then if i click on refresh in the browser it submitted again.
i can redirect to another page to avoid this.but i want to stay in the same feed back page..

here is my code

function feedback()
$data = array();
$data['mainContent'] = $this->load->view('tmbd/feedback', $data, true);
$this->load->view('index', $data);

function feedbackSave()

$data['subject'] = $this->input->post('subject', true);
$data['name'] = $this->input->post('lname', true);
$data['address'] = $this->input->post('address', true);
$data['email'] = $this->input->post('email', true);
$data['mobile'] = $this->input->post('mobile', true);
$data['comments'] = $this->input->post('comments', true);

$datetime = date('Y-m-d H:iConfused');
$data['date'] = $dateTime;

$this->load->model($this->config->item('generalModel'), 'save_feedback',TRUE);

$this->session->set_flashdata('feedback', 'Feedback send successfully');
//maybe it can be solved by using headers function to reload the page....but i dnt knw how to use it?
// thanks in advance for the solution.

I would add another function called "thanks" or whatever you want, then just redirect them if the data is saved successfully.


Then just load your "success" view and any other associated data you may need to pass.

if i redirect then i have to go indifferent page but i want to show the user that same feedback page?

so what to do?

Usually I use if clause to handle this problem.
I catch name of the submit button from view to the if clause.
If the button clicked, the code successfully execute, else do nothing.
Example :

  function feedbackSave()
    if($this->input->post('submit'))//button name depending what you set it
      $data[‘subject’] = $this->input->post(‘subject’, true);
      $data[‘name’] = $this->input->post(‘lname’, true);
      $data[‘address’] = $this->input->post(‘address’, true);
      $data[‘email’] = $this->input->post(‘email’, true);
      $data[‘mobile’] = $this->input->post(‘mobile’, true);
      $data[‘comments’] = $this->input->post(‘comments’, true);
      $datetime = date(‘Y-m-d H:i:s’);
      $data[‘date’] = $dateTime;

      $this->load->model($this->config->item(‘generalModel’), ‘save_feedback’,TRUE);
      $this->session->set_flashdata(‘feedback’, ‘Feedback send successfully’);

Hope I can help you,.

Why not just do a
instead of
. The redirect will clear the POST data and reload the feedback function.

Theme © iAndrew 2016 - Forum software by © MyBB