简体   繁体   中英

Codeigniter Post keeps adding up

Could not think of aa better title for this question. Anyways here is the problem.

I have a simple contact form. If the user goes to that page and enters wrong info (no email or message) then everything seems to work. I get the validation errors. But if they put the wrong information in say 6 times in a row, then click the browsers "back" button. They do not go to the previous page. They have to click 6 or 7 times to return to previous page. Am I doing something wrong?

class Contact extends CI_Controller {

    function index()
    {

        $data['title'] = "Contact Us";
        $data['main'] = 'contact';
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
        $this->form_validation->set_rules('message','Message','required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->vars($data);
            $this->load->view('template');
        }
        else
        {
             $contactdata['username'] = $this->input->post('email');
             $contactdata['title'] = "Contact Success";
             $contactdata['main'] = 'contactsuccess';
             $this->load->vars($contactdata);
             $this->load->view('template');
        }
}

you can check the request if it is come from a post request

class Contact extends CI_Controller {

    function index()
    {

        $data['title'] = "Contact Us";
        $data['main'] = 'contact';

        if($this->input->post()){

               $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
               $this->form_validation->set_rules('message','Message','required');

              if ($this->form_validation->run() == FALSE)
              {
                  $this->load->vars($data);

              }
              else
              {
                 $contactdata['username'] = $this->input->post('email');
                 $contactdata['title'] = "Contact Success";
                 $contactdata['main'] = 'contactsuccess';
                 $this->load->vars($contactdata);
             }
        }
        else{
                 $this->load->vars($data);
        }

        $this->load->view('template');

  } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM