dongtao1262 2013-07-23 15:03
浏览 57

使用会话变量进行CodeIgniter表单验证

How do I get the CodeIgniter form validation to validate the $_SESSION if there is no passed form data? I tried manually setting the $_REQUEST variable, but it doesn't seem to work.

i.e. I have a function search in the controller which validates the form input passed, and either returns you to the previous page with errors, or else moves you onto the next page. But I want this function to also work if you previously filled out this page, and the info is stored in the $_SESSION variable.

function search () {
    $this->load->library("form_validation");
    $this->form_validation->set_rules("flightID", "Flight Time", "required|callback_validFlightID");
    $this->form_validation->set_rules("time", "Flight Time", "required|callback_validFlightTime");

    $this->setRequest(array("flightID", "time"));

    // adding session check allows for inter-view navigation
    if ($this->form_validation->run()) {

        // some application logic here

        $this->load->view("seats", $data);
    } else {
        $this->logger->log($_REQUEST, "request");
        // redirect back to index
        $this->index();
    }   
}
function setRequest () {
    // make sure none of the parameters are set in the request
    foreach ($vars as $k) {
        if (isset($_REQUEST[$k])) {
            return;
        }   
    }   

    foreach ($vars as $k) {
        if (isset($_SESSION[$k])) {
            $_REQUEST[$k] = $_SESSION[$k];
        }   
    }   

}
  • 写回答

3条回答 默认 最新

  • dsds661730652211 2013-07-23 17:38
    关注

    form_validation works directly with $_POST, so use that instead of $_REQUEST.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计