如何获取 CodeIgniter 表单验证以验证$_SESSION
是否没有传递表单数据?我尝试手动设置$_REQUEST
变量,但它似乎不起作用。
即,我在控制器中有一个函数search
,它验证传递的表单输入,或者将您返回到有错误的上一页,或者将您移到下一页。但是,如果您之前填写了此页面,并且信息存储在$_SESSION
变量中,我希望此功能也可以工作。
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];
}
}
}