繁体   English   中英

代码点火器-表单验证(无错误消息)

[英]Code Igniter - Form Validation (No Error Messages)

我在使用Code Igniter遇到了真正的麻烦。 我试图启用错误,但显示的内容无济于事,据我所知,我正确地遵循了文档。 我遇到的问题是模板中的validate_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挂钩会导致表单验证出现问题。

有任何想法吗??

确定修复!

原因与我正在运行并在此问题上显示的代码无关,与我在CodeIgniter中实现钩子的方式有关。 我已经为钩子扩展了核心CI控制器(这是错误的做法)。 我现在修改了挂钩,以使用get_instance()方法检索CI实例,并且设法从挂钩中实现了相同的功能,而不会引起此问题。

所以我的错!

还是要谢谢你的帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM