codeigniter displaying form_open

hey guys was hoping you could help me out.

im trying to learn codeigniter and for some reason i cant do the simplest of things.

basically im creating a form on a login page. but im getting

Fatal error: Call to undefined function validation_errors() in A:\work\codeigniter\ci\application\views\pages\login.php on line 5

and if i comment out the validation_errors line i get

Fatal error: Call to undefined function form_open() in A:\work\codeigniter\ci\application\views\pages\login.php on line 5 ...

Error message

( ! ) Fatal error: Call to undefined function validation_errors() in A:\work\codeigniter\ci\application\views\pages\login.php on line 3
Call Stack
#   Time    Memory  Function    Location
1   0.0004  697328  {main}( )   ..\index.php:0
2   0.0010  790176  require_once( 'A:\work\codeigniter\ci\system\core\CodeIgniter.php' )    ..\index.php:202
3   0.0135  2313080 call_user_func_array ( )    ..\CodeIgniter.php:359
4   0.0135  2313160 Pages->view( )  ..\CodeIgniter.php:359
5   0.0135  2313288 CI_Loader->view( )  ..\pages.php:9
6   0.0135  2314232 CI_Loader->_ci_load( )  ..\Loader.php:419
7   0.0138  2363392 include( 'A:\work\codeigniter\ci\application\views\pages\login.php' )   ..\Loader.php:833

this is my code.

login.php located at view\pages

<?php echo validation_errors(); ?>

<?php echo form_open('user/login') ?>

    <label for="Id"> User Id</label>
    <input type="input" name="Id" /> <br/>

    <label for="Password">User Password</label>
    <input type="input" name="Password" />
    <br/>

    <input type="submit" name="submit" value="log in" />

</form>

user.php located at controllers\

<?php
    class User extends CI_controller{
    public function login()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');

        //i have a file views/pages/main.php which just says "this is main"
        $this->load->view('pages/main'); 
    }
    }

pages.php located at controllers/

<?php

    class Pages extends CI_Controller{
    public function view($page){
        if(!isset($page)||!file_exists("application/views/pages/$page.php")){
        show_404();
        }

        $this->load->view("pages/$page");


    }
    }

routes.php located at config/

$route['default_controller'] = "pages/view";
$route['(:any)']="pages/view/$1";
$route['404_override'] = '';

this is what i think happens and if im wrong please correct me. form_open('user/login') makes the "action" of the html form element point to a method "login" of class "user" located in controlers.

also, i googled a lot and pretty much everyone else that was getting this error was getting it because they hadnt done

$this->load->helper('form');
$this->load->library('form_validation');

also, i dont get the string in form_open points to the location for the "action" attribute in the html form element, why is it neccessary to load form helper and form validation library there? can some explain the flow of this please.. would be really appreciated..thanks..

Answers


basically the problem was that the controller that was calling the view with the form should contain

$this->load->helper('form');
$this->load->library('form_validation');

and not the controller that is being called by the form action


Try loading form helper at your autoload.php file inside config folder.

This would be a good practise:

$autoload['helper'] = array('url','text','form');

Need Your Help

IE8 Php header location opens a new window

php search iframe header window

I have a page dynamically filled with content from PHP and databases, the content is loaded into an iframe. Now when I make a custom search, the results are coming out fine on all browsers BUT IE8 ...

Where in Query with Array in LINQ

c# .net linq linq-to-sql

I have array number = {2,3,4,5,6}