CodeIgniter Forums
Issue with Form Validation library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Issue with Form Validation library (/thread-13083.html)



Issue with Form Validation library - El Forum - 11-10-2008

[eluser]cayasso[/eluser]
Hi All,
I am running into a problem here with CI and form validation and I was hoping
that some one can help me out or point me to the right path. Its been 2 day now
trying to get a solution but still I haven't get one. I have read some other post but cannot find an answer.

It seems that you cannot use form_validation library from a controller that
extends from another controller.
Call to a member function load() on a non-object in
C:\wamp\www\lx2\system\libraries\Form_validation.php on line 316

Can you please help me out in a way of how to load and use form_validation on a
child controller.

Thank you very much and I will really appreciate your help this is very
important for me I am delivering a system :|



I have created a page base controller in application/libraries, this controller has all the funcionality to build the page layout itself.

Code:
class MY_Controller extends Controller
{
function __construct()
{
parent::Controller()
}

function index()
{
//...General code to create a page
}
}

and I have in application/controllers/Comments.php

Code:
class Comments extends MY_Controller
{
function __construct()
{
     parent::__construct();
     $this->load->helper('form');
     $this->load->library('form_validation');
}

function index()
{
    $this->form_validation->set_rules('db_name', 'Username', 'required');
    $this->form_validation->set_rules('db_email', 'Email', 'required');

if($this->form_validation->run() == FALSE)
{
     echo 'FORM IS NOT VALID CHECK BELLOW';
     echo '<h1>'.validation_errors().'</h1>';
}else{
     echo 'YOU ARE SUBMITTING A VALID FORM';
}


     echo form_open('comments');
     echo form_label('Name ', 'name');
     echo form_input(array(
             'name' => 'db_name',
             'size' => '50',
             'maxlength' => '255',
             'value' => 'hay muchos valores en esta caja'
         )).'<br />';

     echo form_label('Email ', 'email');
     echo form_input(array(
             'name' => 'db_email',
             'size' => '50',
             'maxlength' => '255',
             'value' => 'hay muchos valores en esta caja'
         )).'<br />';
     echo form_submit('', 'Submit', 'class="submit"');
     echo form_close();
}
}



Issue with Form Validation library - El Forum - 11-10-2008

[eluser]bastones[/eluser]
Not sure if you can do that at all, as I tried something similar sometime a go. You can create a library, and then call the library and the corresponding function in that library. It's just like doing ordinary code and you can call it inside your code and you won't need to extend the library class.

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