Welcome Guest, Not a member yet? Register   Sign In
Strange issue with validation libraries
#1

[eluser]daweb[/eluser]
Hi guys,

I'm running (on line) PHP 5.2.2

In my localhost, instead, 5.1.x

I have this controller:

Code:
class Login extends Controller {

    function __construct()
    {
        parent::Controller();      
        $this->load->library('validation');
        // I HAVE TO ADD THIS LINE TO MAKE VALIDATION WORKING, BUT JUST ONLINE!! //
        $this->load->model('settings_model', 'set');
        // THIS IS A SIMPLE MODEL WITH QUERIES TO DATABASE, THAT'S IT!! //
    }

    function index()
    {
        $data_stack['pageTitle']   = $this->lang->line('titleLogin');
        $this->load->view('admin/custom_validation/logins_validation.php', '', FALSE);
        if($this->validation->run() == TRUE)
        {
            redirect('front', 'location');
            exit();
        }

        $this->load->view('admin/login/index', $data_stack);
    }
} // END Front


Ok! On line and just on line, I had to add $this->load->model('settings_model', 'set') or $this->validation doens't work: it doens't return error array.

Why????
#2

[eluser]xwero[/eluser]
You have no rules?
#3

[eluser]daweb[/eluser]
Hi xwero,

no, I have my rules in an external file:

Code:
$this->load->view('admin/custom_validation/logins_validation.php', '', FALSE);
#4

[eluser]daweb[/eluser]
This is my external file:

Code:
<?php
    $rules['username'] = 'trim|required|min_length[5]|max_length[200]';
    $rules['password'] = 'trim|required|min_length[5]|max_length[200]|callback_check_login';
    $this->validation->set_rules($rules);

    $fields['username'] = $this->lang->line('formUsername');
    $fields['password'] = $this->lang->line('formPassword');
    $this->validation->set_fields($fields);
?>

It works fine in all my controllers (bambooinvoices dictat :-))
#5

[eluser]xwero[/eluser]
and that has worked before?

I think it's a misuse of the loader class. I think you are better of with an include.
#6

[eluser]xwero[/eluser]
Ok if it works it works Smile

I see you have a callback. Is it defined in your controller?
#7

[eluser]daweb[/eluser]
I don't think this is a problem.

I have the same trouble if I put rules inside my controller:

Code:
function index()
    {
        $data_stack['pageTitle']   = $this->lang->line('titleLogin');
        //$this->load->view('admin/custom_validation/logins_validation.php', '', FALSE);
        $rules['username'] = 'trim|required|min_length[5]|max_length[200]';
        $rules['password'] =   'trim|required|min_length[5]|max_length[200]|callback_check_login';
    $this->validation->set_rules($rules);

    $fields['username'] = $this->lang->line('formUsername');
    $fields['password'] = $this->lang->line('formPassword');
    $this->validation->set_fields($fields);        

if($this->validation->run() == TRUE)
        {
            redirect('front', 'location');
            exit();
        }

        $this->load->view('admin/login/index', $data_stack);
    }

It still doens't works: I have to put-in my settings model to make it work! I can't understand.
#8

[eluser]xwero[/eluser]
I think the problem is your callback. I guess it's a method of your model.

I've read in a thread the function must be defined in your controller to make the callback work.

I think the easiest way to solve this is to extend the Validation library with a check_login method because you are going to use it on most of your pages. And call the check method from the model there.

I'm busy hacking the validation library to make it validate more input (file and post values), display different error messages for the same rule and instead of callbacks for model methods there will be a catch all model rule.
Code:
$rules['password'] = 'model[Modelname,modelmethod,additional,parameters]';

I've been thinking and rethinking it for some time now but now i have an idea on how to do it so i hope to show the hacked library soon.
#9

[eluser]daweb[/eluser]
Another no Xwero.

The callback function is a method of my controller.

Code:
<?php
class Login extends Controller {

    function __construct()
    {
        parent::Controller();
        $this->load->helper('form');
        $this->load->helper('security');
        // utente non autorizzato
        $this->authUser = FALSE;          
        $this->load->library('validation');
        $this->load->model('settings_model', 'set');
    }

    function index()
    {
        $data_stack['pageTitle']   = $this->lang->line('titleLogin');
        $this->load->view('admin/custom_validation/logins_validation.php', '', FALSE);
        if($this->validation->run() == TRUE)
        {
            redirect('front', 'location');
            exit();
        }

        $this->load->view('admin/login/index', $data_stack);
    }
    
    function check_login()
    {
      $username = $this->input->post('username');
      $password = dohash($this->input->post('password'));
      if ($this->erkanaauth->try_login(array('username'=>$username, 'password'=>$password)))
      {
        $this->erkanaauth->updateLastVisit();
        return TRUE;
      }
      else
      {
        $this->validation->set_message('check_login', 'Errore, utente e/o password errati');
        return FALSE;
      }
    }
} // END Front
?>
#10

[eluser]xwero[/eluser]
And if you set the third parameter from the load model to true?
Code:
$this->load->model('settings_model', 'set',true);




Theme © iAndrew 2016 - Forum software by © MyBB