Bruno Jorge
Bruno Jorge

Reputation: 61

CodeIgniter Drivers and Libraries

I'm tryint to create a driver that validates my form. So, in the controler I load the driver and then the my validation form, like this:

Controller:

(...)

    $this->load->driver('user');
    $this->user->register->validate_form($config);
(...)

Driver:

public function validate_form($config){


        $this->form_validation->set_rules($config);

            if ($this->form_validation->run() == FALSE){

(...)

The error message is:

Message: Call to a member function set_rules() on a non-object

Anyone know what is the problem? Form_validation is loaded.

Upvotes: 0

Views: 145

Answers (1)

Jalin
Jalin

Reputation: 95

You just create a validation class like below

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Validation{
	public	$v_required ='required|trim';

	//Valid name
	public	$v_name ='trim|min_length[3]|max_length[15]|regex_match[/^[A-Za-z][A-Za-z0-9 .]+$/]';
  public  $v_name_msg=array('required'=>'Provide %s.','regex_match'=>'Must starts with alphabet,No special chars are allowed.');
 }
 ?>
 
 After call this to your controller like
 
 require_once(APPPATH."controllers/classes/Validation.php");
 
 After creare a object and use validation class
 
 $da=new validation();
 $this->form_validation->set_rules('name','Name',$da->v_name,$da->v_name_msg);

Upvotes: 0

Related Questions