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

标签 php forms codeigniter validation

<分区>

当我加载模型并从表中获取行时,我的表单验证错误没有在 View 文件中显示消息。这是我的代码。

        $this->form_validation->set_rules('bookCategoryId', 'Book SubCategory Id', 'trim|required');
        $this->form_validation->set_rules('bookSubCategoryId', 'Book SubCategory Id', '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

关于php - codeigniter 表单验证错误消息不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18573746/

相关文章:

forms - 如何在移动到下一张幻灯片之前验证 ionic 幻灯片中的表单?

php - 表单中的选项输入未通过

php - 如何将 Codeigniter 中的welcome.php 更改为类似index.php 的内容?

mysql - Codeigniter session 值访问

php - Symfony2 - 如何使用带有 Doctrine MongoDB ODM 的 postLoad 事件监听器来更改文档?

php - CakePHP 2 从 Controller 方法访问模型常量

php - 如何在 WordPress 中显示来自 get_children 数组的特定图像

php - Wordpress 单篇文章内容侧边栏

java - Spring表单验证不返回错误消息

codeigniter - 您的服务器不支持处理此类图像所需的 GD 功能。Ci