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.

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

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接