Welcome Guest, Not a member yet? Register   Sign In
help! validation class doesnt work!
#1

[eluser]Unknown[/eluser]
controller:
Code:
<?php
class Form extends Controller {

function index()
{
  $this->load->helper(array('form', 'url'));
  
  $this->load->library('validation');
    
  if ($this->validation->run() == FALSE)
  {
   $this->load->view('register');
  }
  else
  {
   $this->load->view('reg_success');
  }
}
}
?>


i just do as the example in the user guide, but the script returns an error:
Code:
A PHP Error was encountered
Severity: Notice

Message: Undefined property: Register::$validation

Filename: controllers/register.php

Line Number: 20


Fatal error: Call to a member function run() on a non-object in F:\ciblog\system\application\controllers\register.php on line 20

what's wrong with my script?
thanks
#2

[eluser]tonanbarbarian[/eluser]
Something strange going on here
Your error says that the controller is called register yet your code says it is called Form
please make sure you are including the correct code
#3

[eluser]xwero[/eluser]
I guess you copied the snippet from the userguide. There is one error in it
Code:
if ($this->validation->run() === FALSE)
This example is only to show how to implement the validation library it's not meant to use on a working site.
You should a least have one rule.
#4

[eluser]Unknown[/eluser]
well, this is my real code:

controllers/register.php
Code:
<?php
class Register extends Controller {

    function Register()
    {
        parent::Controller();
        $this->load->helper("form");
        
    }
    
    function index()
    {
        $view_data = array(
            'title' => 'Register',
            'css' => 'blue.css',
        );
        
        $this->load->library('validation');
    
        $rules['username'] = "required";
        $rules['password'] = "required";
        $rules['password2'] = "required";
        $rules['nickname'] = "required";
        $rules['email'] = "required";

        $this->validation->set_rules($rules);
        if ($this->validation->run() == FALSE)
        {
            $view_data['content'] = 'form'; // print register form
        }
        else
        {
            //insert into database
            //
            
            $view_data['content'] = 'success'; // print success msg
        }
        $this->load->view($this->config->item('template').'/register',$view_data);
    }
}
?>

and this is the error msg:
Code:
A PHP Error was encountered
Severity: Notice

Message: Undefined property: Register::$validation

Filename: controllers/register.php

Line Number: 26


Fatal error: Call to a member function set_rules() on a non-object in F:\ciblog\system\application\controllers\register.php on line 26

this is very strange! i have used print_r($this) after loading the validation library, but i didn't see anything about the validation object
#5

[eluser]xwero[/eluser]
And you do have the validation.php file in the system/libraries directory? Maybe you got a bad CI download




Theme © iAndrew 2016 - Forum software by © MyBB