繁体   English   中英

会话 flashdata 不适用于表单提交

[英]Session flashdata doesn´t work on form submit

我正在为 codeigniter ( https://github.com/benedmunds/CodeIgniter-Ion-Auth ) 使用 ion-auth “库”,但我遇到了 flashdata 的问题。 这是代码摘要:

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
        }
    }
}

好吧,提交表单时 $this->session->flashdata('csrfvalue') 的 echo 总是什么都不显示。
如果我做这样的事情:

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>";
}

在这种情况下......它有效。 我使用的表单视图与此非常相似: https : //github.com/benedmunds/CodeIgniter-Ion-Auth/blob/2/views/auth/reset_password.php

谢谢。

解决方案

经过一番斗争,我正在寻找可以在加载表单视图和提交表单之间发出新请求的东西......最后,我发现(我不记得)一个通过控制器请求的javascript (根据本教程翻译一些文本: http : //www.student.kuleuven.be/~r0304874/blog/international-javascript-files-in-codeigniter.html )。 我是这样加载的:

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

谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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