dongqiu3254 2013-01-09 08:17
浏览 6

Codeigniter Post不断加起来

Could not think of a a 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');
        }
}
  • 写回答

1条回答 默认 最新

  • duanru6816 2013-01-09 08:25
    关注

    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');
    
      } 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?