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

[eluser]ranjitbd[/eluser]
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=array();

$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->save_feedback->feedbackSave($data);

$this->session->set_flashdata('feedback', 'Feedback send successfully');
$this->feedback();
}
//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.
#2

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

Code:
redirect('feedback/thanks');

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

[eluser]ranjitbd[/eluser]
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?
#4

[eluser]budbud[/eluser]
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 :

Code:
<?php
  function feedbackSave()
  {
    if($this->input->post('submit'))//button name depending what you set it
    {
      $data=array();
    
      $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->save_feedback->feedbackSave($data);
    
      $this->session->set_flashdata(‘feedback’, ‘Feedback send successfully’);
      $this->feedback();
    }
  }
?>

Hope I can help you,.
#5

[eluser]lordmontie[/eluser]
Why not just do a
Code:
redirect('/controller/feedback/');
instead of
Code:
$this->feedback();
. The redirect will clear the POST data and reload the feedback function.




Theme © iAndrew 2016 - Forum software by © MyBB