我有一个关于使用 Codeigniter 和 Flash Data 进行表单验证的问题。我的表单位于 URL 字符串的深处,因此我认为在页面上显示错误消息的最佳方式是使用 CI 闪存数据。我很难弄清楚如何实际显示错误消息。我不确定我哪里出错了。我哪里错了?感谢大家。
public function form_validate_cars()
{
$this->load->library('form_validation');
$this->form_validation->set_rules("value", "<b>Value</b>", "trim|required|is_numeric|xss_clean");
$this->form_validation->set_rules("exterior_color", "<b>Exterior Color</b>", "trim|required|xss_clean");
$this->form_validation->set_rules("interior_color", "<b>Interior Color</b>", "trim|required|xss_clean");
$this->form_validation->set_rules("mileage","<b>Mileage</b>","trim|required|is_numeric|xss_clean");
if ($this->form_validation->run() == FALSE)
{
// if person does not fill in correct info, they get resubmitted back to the form.
// redirect('site/item/2332');
// echo 'Hello World!';
$msg = "Please fill out proper data";
$this->session->set_flashdata('test', $msg);
// echo 'Please fill out needed ifnormation!';
}
else
{
$this->load->model('model_data');
$this->model_data->add_new_value();
redirect('/site/thanks');
}
}
我的观点
echo form_open('site/form_validate_cars');
print_r($this->session->flashdata('test'));
echo validation_errors();
my form continues below .......