加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – codeigniter表单验证错误消息不显示

发布时间:2020-12-13 13:09:35 所属栏目:PHP教程 来源:网络整理
导读:当我加载模型并从表中获取行时,我的表单验证错误不会在视图文件中显示消息.这是我的代码. $this-form_validation-set_rules('bookCategoryId','Book SubCategory Id','trim|required'); $this-form_validation-set_rules('bookSubCategoryId','trim|required
当我加载模型并从表中获取行时,我的表单验证错误不会在视图文件中显示消息.这是我的代码.
$this->form_validation->set_rules('bookCategoryId','Book SubCategory Id','trim|required');
        $this->form_validation->set_rules('bookSubCategoryId','trim|required');
        $this->form_validation->set_rules('bookSubCategoryName','Book SubCategory Name','trim|required');
if ($this->form_validation->run() == FALSE) {
        /* Load Model */
        $this->load->model('book_category');

        /* Get Categories */
        $template_data['mainContentData']['book_categories'] = $this->book_category->get_all_categories();

        /* set view page to be called  */
        $template_data['mainContent'] = 'admin_add_book_subcategory';

        /* Load Template */
        $this->template($template_data);
    }

如果我排除这两行,我的表单工作正常

/* Load Model */
        $this->load->model('book_category');

        /* Get Categories */
        $template_data['mainContentData']['book_categories'] = $this->book_category->get_all_categories();

比我的验证显示错误.我不知道问题出在哪里?

您应该使用validation_errors函数
<?php echo validation_errors(); ?>

文档3.x:validation_errors

文件2.x:form_validation

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读