Fatal error: calling undefined validation_errors () function with codeIgniter

Fatal error: calling undefined validation_errors () function using codeIgniter here is my comment .php view

        <?php echo validation_errors(); ?>

        <?php echo form_open('news/comments'); ?>

            Name   <input type="text" name="comment_name"></input><br />
            Email  <input type="text" name="comment_email"></input><br />
            Comment<input type="text" name="comment_body"></input><br />
            <input type="submit" name="submit" value="Comment it" ></input>

        </form>

here news_model.php

<?php
class News_model extends CI_Model {

public function __construct()
{
    $this->load->database();
}



//set comment

public function set_comment()
{
$this->load->helper('url');
$this->load->helper('date');

$data_c = array(
    'comment_name' => $this->input->post('comment_name'),
    'comment_email' => $this->input->post('comment_email'),
    'comment_body' => $this->input->post('comment_body'),   
);

    return $this->db->insert('comments', $data_c);
}

}

here is my controller news.php

<?php
class News extends CI_Controller {

public function __construct()
{
    parent::__construct();
    $this->load->model('news_model');


}



public function create_comment()
{
$this->load->helper('form');
$this->load->library('form_validation');


$this->form_validation->set_rules('comment_name', 'comment_name', 'required');
$this->form_validation->set_rules('comment_email', 'comment_email', 'required');
$this->form_validation->set_rules('comment_body', 'comment_body', 'required');

if ($this->form_validation->run() === FALSE)
{
    echo 'failed'; //just for debugging

}
else
{
    $this->news_model->set_comment();
    $this->load->view('news/success');
}   


}

}

in routes.php

$route['news/comments'] = 'news/comments';

How to allow? It is not possible to insert data into the database due to a fatal error.

+4
source share
2 answers

I don’t see that you are loading your validation_form library anywhere - are you sure it is loaded?

Either at startup, or otherwise:

$this->load->library('form_validation');
+10
source

. , HTML . , .

Name   <input type="text" id="comment_name"  name="comment_name"></input><br />
Email  <input type="text" id="comment_email" name="comment_email"></input><br />
Comment<input type="text" id="comment_body"  name="comment_body"></input><br />
0

All Articles