doutang6600 2016-03-23 01:33
浏览 31
已采纳

会话flashdata不适用于表单提交

I am using the ion-auth "library" for codeigniter (https://github.com/benedmunds/CodeIgniter-Ion-Auth) and I am getting a trouble with the flashdata. This is a sumary of code:

public function reset_password($code = NULL)
{
    if (!$code)show_404();
    $this->user = $this->ion_auth->forgotten_password_check($code);
    if ($this->user)
    {
        //setting the rules
        if ($this->form_validation->run() == false)
        {
            //more code
            $this->_get_csrf_nonce();
            /*
              One of the things this function (_get_csrf_nonce) makes is:
              $this->session->set_flashdata('csrfkey', $key);
              $this->session->set_flashdata('csrfvalue', $value); 
            */
            //The next thing is load the view with the form
        }
        else //form is running
        {
            echo "flashdata csrfkeyvalue: ".$this->session->flashdata('csrfvalue')."<br>";
            die;
            //more code, but not important by the moment
        }
    }
}

Well, the echo of $this->session->flashdata('csrfvalue') when the form is submited allways show nothing.
If I make something like:

private function _get_csrf_nonce(){
    /*$this->load->helper('string');
    $key   = random_string('alnum', 8);
    $value = random_string('alnum', 20);
    $this->session->set_flashdata('csrfkey', $key);*/
    $this->session->set_flashdata('csrfvalue', $value);
    redirect(base_url("auth/test"));
    //return array($key => $value);
}
public function test()
{
    echo "flashdata csrfkeyvalue: ".$this->session->flashdata('csrfvalue')."<br>";
}

In this case... it works. The view I am using to the form is very very similar from this: https://github.com/benedmunds/CodeIgniter-Ion-Auth/blob/2/views/auth/reset_password.php

Thanks.

  • 写回答

1条回答 默认 最新

  • dongyizhuang0134 2016-03-23 01:33
    关注

    SOLUTION

    After fighting a little, I was looking for something that could make a new request between the view of form was loaded and the form was submited... finally, I discover (I didn´t remember) a javascript that is request though a controller (to translate some texts, based on this tutorial: http://www.student.kuleuven.be/~r0304874/blog/international-javascript-files-in-codeigniter.html). I was loaded in this way:

    <script src="<?=site_url('jsloader/login.js');?>" type="text/javascript"></script>
    

    Thanks.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器