Encoding form validation error message does not appear

my form validation error does not display messages in the view file when loading the model and retrieving a row from the tables. here is my code.

$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); } 

My form works fine if I exclude these two lines

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

than my checks show an error. I do not know where the problem is?

+8
php validation forms codeigniter
source share
4 answers

You must use the validation_errors function

 <?php echo validation_errors(); ?> 

Documentation 3.x: validation_errors

Documentation 2.x: form_validation

+4
source share

Try changing it to this:

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

Simulation of the first letter capitalized in accordance with the CI documentation

Link: http://ellislab.com/codeigniter/user-guide/general/models.html

This is from the man page:

Model classes are stored in the application / models / folder. They can be nested in subfolders if you want this type of organization.

The main prototype for the model class is the following:

 class Model_name extends CI_Model { function __construct() { parent::__construct(); } } 

Where Model_name is the name of your class. Class names must have the first letter with a capital letter with the rest of the name in lower case. Make sure your class extends the base class of the model.

The file name will be the bottom version of your class name. For example, if your class:

 class User_model extends CI_Model { function __construct() { parent::__construct(); } } 

Your file will be as follows:

 application/models/user_model.php Loading a Model 

Your models will typically be loaded and called from your controller functions. To load the model, you will use the following function:

 $this->load->model('Model_name'); 
0
source share

Sorry, my mistake. I mistakenly inherit my model class (book_category) using CI_controller Instead of the CI_Model class

0
source share

Try it....

  /* 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'; $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()) { print_r($_POST); exit; } /* Load Template */ $this->template($template_data); 
0
source share

All Articles