Php 使用codeigniter查看表单验证结果
这是表单的URL 这就是我验证它的方式。但问题是我无法在页面上显示验证错误Php 使用codeigniter查看表单验证结果,php,forms,codeigniter,validation,url,Php,Forms,Codeigniter,Validation,Url,这是表单的URL 这就是我验证它的方式。但问题是我无法在页面上显示验证错误 $this->form_validation->set_rules('password', 'Password', 'required'); $this->form_validation->set_rules('confirmpassword', 'Password Confirmation', 'required|matches[password]');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('confirmpassword', 'Password Confirmation', 'required|matches[password]');
if ($this->form_validation->run() == FALSE) {
redirect($_SERVER['HTTP_REFERER']);
}
你可以试试CI flash数据
$this->session->set_flashdata('errors', validation_errors());
redirect($_SERVER['HTTP_REFERER']);
它会为下一个服务器请求保留数据。您可以尝试CI flash数据
$this->session->set_flashdata('errors', validation_errors());
redirect($_SERVER['HTTP_REFERER']);
它为下一个服务器请求保留数据。好的,我遇到了一些可以改进的问题
首先,当字段无效时,为什么要将用户重定向到某个位置?为什么不使用:
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('confirmpassword', 'Password Confirmation', 'required|matches[password]');
if ($this->form_validation->run()) {
redirect(base_url('emailSend'); // or wherever you want the visitor to be send to
}
$this->load->view('register'); // or however your view file is called
这样,如果您的视图文件中有规则
,
是
的短php代码,验证错误()
应该包含验证错误(如果有)。好的,我遇到了一些可以改进的问题
首先,当字段无效时,为什么要将用户重定向到某个位置?为什么不使用:
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('confirmpassword', 'Password Confirmation', 'required|matches[password]');
if ($this->form_validation->run()) {
redirect(base_url('emailSend'); // or wherever you want the visitor to be send to
}
$this->load->view('register'); // or however your view file is called
这样,如果您的视图文件中有规则
,
是
的短php代码,验证错误()
应该包含验证错误(如果有)。请同时发布查看代码。请同时发布查看代码。感谢您的想法。但是你能展示一下如何在视图中显示它吗?在视图中,使用$this->session->flashdata('errors');表达对这个想法的感谢。但是你能展示一下如何在视图中显示它吗?在视图中,使用$this->session->flashdata('errors');显示消息哦!事实上,我没有试过,因为我认为它不会引起问题,也不会起作用。但是成功了。谢谢。很高兴能帮助你哦!事实上,我没有试过,因为我认为它不会引起问题,也不会起作用。但是成功了。谢谢。很高兴能帮助你