• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
blog form

#1
BLOG FORM

Fatal error: Call to undefined function validation_errors() in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\blog\application\views\blog_form.php on line 11

A PHP Error was encountered

Severity: Error

Message: Call to undefined function validation_errors()

Filename: views/blog_form.php

Line Number: 11

Backtrace:

------------------------------------------




views\blog_form.php


PHP Code:
Code:
<html>

<title>Blog Form</title>

<br>

<h1>BLOG FORM</h1>


<?php echo validation_errors(); ?>

<?php echo form_open('form'); ?>


<table>

<tr>
<td>Date  :</td>
<td><input type="text" name="username" value="" size="50" /></td>
</tr>
<tr>
<td>Upload  :<br><br></td>
</tr>
<tr>
<td>Title :</td>
</tr>
<tr>
<td>Content :</td>
</tr>

<div><input type="submit" value="Submit" /></div>

</form>
</table>


</html> 

An error appears:

views/blog_form.php

Line 11:  <?php echo validation_errors(); ?>


How to fix line 11 ?



controllers\blog.php

PHP Code:

Code:
<?php


class Blog extends CI_Controller {

        public function index()
        {
                $this->load->model('blog_model');

                $data['title'] = $this->blog_model->select_blog();
                $data['content'] = $this->blog_model->select_blog();
" If I looks more intelligence please increase my reputation."
Reply

#2
Load load load:

http://www.codeigniter.com/user_guide/li...controller
Reply

#3
routes.php

PHP Code:
$route['blog_form'] = 'blog/blog_form';
$route['default_controller'] = 'blog/blog_form';

$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE



views/blog_form.php

PHP Code:
<html>

<
title>Blog Form</title>

<
br>

<
h1>BLOG FORM</h1>


<?
php echo validation_errors(); ?>

<?php echo form_open('form'); ?>


<table>

<tr>
<td>Date  :</td>
<td><input type="text" name="username" value="" size="50" /></td>
</tr>
<tr>
<td>Upload  :<br><br></td>
<td><input type="text" name="username" value="" size="50" /></td>
</tr>
<tr>
<td>Title :</td>
<td><input type="text" name="username" value="" size="50" /></td>
</tr>
<tr>
<td>Content :</td>
<td><input type="text" name="username" value="" size="50" /></td>
</tr>

<div><input type="submit" value="Submit" /></div>

</form>
</table>


</html> 



BLOG FORM

Fatal error: Call to undefined function validation_errors() in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\blog\application\views\blog_form.php on line 11
A PHP Error was encountered
Severity: Error
Message: Call to undefined function validation_errors()
Filename: views/blog_form.php
Line Number: 11
Backtrace:


Line 11:  <?php echo validation_errors(); ?>
" If I looks more intelligence please increase my reputation."
Reply

#4
Like Cartalot said, this usually happens when you do not load the form helper in the controller.

PHP Code:
$this->load->helper('form'); 

Best wishes,

Paul
Reply

#5
I already load the helper.


controllers/blog.php


PHP Code:
<?php


class Blog extends CI_Controller {

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

                
 
               $this->load->model('blog_model');

 
               $data['title'] = $this->blog_model->select_blog();
                
$data['content'] = $this->blog_model->select_blog();
                
$data['date'] = $this->blog_model->select_blog();
                
                
$this->load->view('blog'$data);
                                            
                
//$this->load->view('blog');
 
       
        
}
        
        public function 
blog_form()
        {
                
$this->load->view('blog_form');
                                
        }
}



?>
" If I looks more intelligence please increase my reputation."
Reply

#6
The index() method does not run when you are routed to the blog_form() method. If you want code to run for every method in a controller, you need to create a constructor:

PHP Code:
class Blog extends CI_Controller 
{
 
   public function __construct()
 
   {
 
       parent::__construct();

 
       $this->load->helper(array('form''url'));
 
       $this->load->library('form_validation');
 
       $this->load->model('blog_model');
 
   }

 
   public function index()
 
   {
 
       $data['title'  $this->blog_model->select_blog();
 
       $data['content'] = $this->blog_model->select_blog();
 
       $data['date'   $this->blog_model->select_blog();
 
       
        $this
->load->view('blog'$data);
 
   }
 
   
    public 
function blog_form()
 
   {
 
       $this->load->view('blog_form');
 
   }

Reply

#7
BLOG FORM

Date:    I   I   I    I

Upload:   Image

Title:     Title

Content:    Content




Hello,

Can anyone help me fix the code so that whenever someone input in the views/blog_form.php

Upload:  [ upload ]

Title:  [  title  ]

Content:  [   content  ]

It truely place and move the code to the database through model.  Can anyone help me to fix it?



views/blog_form.php


PHP Code:
<html>

<
title>Blog Form</title>

<
br>

<
h1>BLOG FORM</h1>

<?
php echo validation_errors(); ?>

<?php echo form_open('blog'); ?>

<table>

<tr>
<td>Date  :</td>
<td><?php echo $this->calendar->generate();  ?></td>
</tr>
<tr>
<td>Upload  :<br><br></td>
<td><input type="file" name="pic" id="pic"><br></td>
</tr>
<tr>
<td>Title :</td>
<td><input type="text" name="username" value="" size="30" /></td>
</tr>
<tr>
<td>Content :</td>
<td>
<textarea rows="8" cols="40">

</textarea>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" /></td>
</tr>
</form>
</table>


</html> 



controllers/blog.php

PHP Code:
<?php


class Blog extends CI_Controller {

        
// If you want code to run for every method in a controller, you need to create a constructor
 
       
        
public function __construct()
 
       {
                
parent::__construct();
                
                
$this->load->helper('date');                 
                
$this->load->helper('form');  
                $this
->load->library('calendar');                          
                $this
->load->library('form_validation');
 
               $this->load->model('blog_model');
        }        
                
        public function 
index()
        {
            
 
               $data['title'] = $this->blog_model->select_blog();
                
$data['content'] = $this->blog_model->select_blog();
                
$data['date'] = $this->blog_model->select_blog();
                
                
$this->load->view('blog'$data);
                                
        }
        
        public function 
blog_form()
        {
                
$this->load->view('blog_form');
                                
        }
}



?>


model/blog_model.php

PHP Code:
<?php



class Blog_model extends CI_Model {

        public $title;
        public $content;
        public $date;

        public function __construct()
        {
                // Call the CI_Model constructor
                parent::__construct();
                
                $this
->load->database();
        }

        public function select_blog()
        {
            
                $query 
$this->db->query('SELECT * FROM blog');

                return $query->result();
                //  return  'masuk loh';
        }
        
        
public function insert_blog()
        {
                $this->title    $_POST['title']; // please read the below note
                $this->content  $_POST['content'];
                $this->date     time();

                $this->db->insert('blog'$this);
        }

        public function update_blog()
        {
                $this->title    $_POST['title'];
                $this->content  $_POST['content'];
                $this->date     time();

                $this->db->update('blog'$this, array('id' => $_POST['id']));
        }

}



?>
" If I looks more intelligence please increase my reputation."
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.