【发布时间】:2012-03-03 11:59:11
【问题描述】:
我在使用 Code Igniter 时遇到了问题。我试图启用显示没有任何用处的错误,据我所知,我正确地遵循了文档。我遇到的问题是模板中的 validation_errors() 函数没有回显验证问题。验证过程正在工作(如果验证失败,它将返回到表单)但是没有显示错误消息。此外,set_values() 函数不会使用刚刚输入的信息填充字段,而是使用默认值填充。
tpl 文件非常基本,并且具有正确的功能等,因此不包括在内(大),但是我已经包含了下面控制器中的方法。
// Setup Error Specifics
$this->form_validation->set_error_delimiters('<div class="nNote nFailure hideit"><p><strong>FAILURE: </strong>', '</p></div>');
$this->form_validation->set_rules('company_name', 'Company Name', 'required');
$this->form_validation->set_rules('telephone_no', 'Telephone Number', 'required|is_natural');
$this->form_validation->set_rules('email_address', 'Email Address', 'required|valid_email');
// Begin Validation
if($this->form_validation->run() === false) {
$data = array();
$data['company_info'] = $this->company_model->get_company($this->input->get('company_id'));
$this->load->view('common/header');
$this->load->view('company/edit', $data);
$this->load->view('common/footer');
} else {
$this->session->set_flashdata('success_message', 'You have updated the company record(s)');
redirect('customer/company/listing', 'location');
}
感谢您的帮助, 谢谢!
更新---
在深入了解 CodeIgniter 的核心之后,我已将问题的搜索范围缩小到我正在使用的一些钩子上。我已经完全注释掉了两个钩子(都是 post_controller_constructor 钩子)的方法代码。即使注释掉了每个钩子的代码,表单验证仍然失败。看来(除非我走错了路) post_controller_constructor 挂钩会导致表单验证出现问题。
有什么想法吗??
【问题讨论】:
-
更新:我已经自动加载了所需的帮助程序/库等。
-
能把视图中的相关代码贴出来吗?
-
直接从视图顶部:
公司编辑器
-
你是在表单动作中调用相同的方法,对吧?代码看起来不错......无关的旁注:使用 is_natural() 作为电话号码验证可能会让用户有点沮丧(如果你没有得到一些 js 掩码的帮助)
-
同样的方法,老实说,第一次使用 Code Igniter 的表单验证功能,所以现在只是在玩,规则不是最终的。有什么想法可以去哪里吗?我看不出有什么问题...
标签: php validation codeigniter