我无法弄清楚问题是什么。当控制器中的var_dump
但在视图中无法看到时,控制器中会显示表单验证错误。
function submitform() {
$pid = 16;
$data['query'] = $this->viewmodel->get_page($pid);
$data['notices'] = $this->viewmodel->get_notices();
$data['events'] = $this->viewmodel->get_events();
$data['gadgets'] = $this->viewmodel->get_gadgets();
$this->load->library(array('form_validation', 'session'));
$this->form_validation->set_rules('fname', 'Full Name', 'required|xss_clean|max_length[100]');
$this->form_validation->set_rules('p_address', 'Permanet Address', 'required|xss_clean|max_length[200]');
$this->form_validation->set_rules('captcha', 'Captcha', 'callback_validate_captcha');
if (($this->form_validation->run() == FALSE)) {
var_dump(validation_errors()); //Validation error is show here but not in view.
die;
$this->load->view('header');
$this->load->view('register', $data);
$this->load->view('eventsfull', $data);
$this->load->view('sitemapcontent', $data);
$this->load->view('footer', $data);
} else {
$name = $this->input->post('fname');
$p_address = $this->input->post('p_address');
$this->viewmodel->add_alumni($fname, $p_address);
$this->session->set_flashdata('message', 'Your request has been submited for verify.');
$data['error'] = "Your data submitted sucessfully.";
}
redirect('sres/register');
}
<?php echo validation_errors(); ?>
//FORM element
答案 0 :(得分:3)
仅当您的视图加载为$this->load->view()
时,表单验证库才有效。在重定向中它将无法工作。您可以使用会话闪存数据在重定向视图中传递错误。
$this->session->set_flashdata('errors', validation_errors());
现在查看文件
<?php var_dump($this->session->flashdata('errors')); ?>