CodeIgniter Forums

Full Version: [SOLVED] validation_errors() returning empty
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]ggoforth[/eluser]
Hey All,

Can't for the life of me figure this one out. In all my controllers I user the form validation lib (it's autoloaded). It works perfectly in all controllers.....except one. In one of my controllers it seems to be loaded (I am setting the rules and using the run() funciton which returns false, however validation_errors() is always empty. It's not returning anything for the errors. Can't for the life of me figure it out. Any ideas?

Greg

EDIT: I'm an idiot who should not be behind a keyboard without at least 8 hours of sleep. 3 hours of sleep + 5 red bulls != 8 hours sleep Smile

El Forum

[eluser]David Johansson[/eluser]
what are you doing diffrent in the controller where it won't work? it sounds like you have some problem setting the rules...

El Forum

[eluser]Thorpe Obazee[/eluser]
or if you are loading the error messages from a language file, make sure they are correctly set or loaded.

El Forum

[eluser]ggoforth[/eluser]
[quote author="David Johansson" date="1248415823"]what are you doing diffrent in the controller where it won't work? it sounds like you have some problem setting the rules...[/quote]

Absolutely nothing that I can see. Standard controller, the validation lib is auto loaded, and I copied and pasted the code for set_rules() from the controller where it's working fine (and changed the field names). I'm totally stumped. I've literally gone line by line, I'll post some code, but I can't see where the problem my be. The function in question is "run_reg".
Code:
<?

    class Booker extends Controller{
    
        public function __construct(){
            parent::Controller();
            $this->load->model('booker_model');
            $this->load->model('contractor_model');
        }
        
        public function index($provider = NULL){
            $data = NULL;
            if(!is_null($provider)){//we have a provider
                if($this->_provider_exists($provider)){//and the provider exists
                    //set the provider contractor_id
                    $contractor = $this->contractor_model->get_contractor_by_username($provider);
                    $this->dbsession->set_userdata(array('provider_id'=>$contractor['contractor_id'],'provider'=>$provider));
                    
                    $this->viewloader->booker_render('login_register_view',$data,$provider);
                }else{//and the provider does not exists
                    $this->viewloader->direct_render('/booker/no_provider',$data);
                }
            }else{//we dont' have a provider
                $this->viewloader->direct_render('/booker/no_provider',$data);
            }
        }
                
        public function run_reg(){
            $this->form_validation->set_rules('fname','First Name','required|trim');
            $this->form_validation->set_rules('lname','Last Name','required|trim');
            $this->form_validation->set_rules('email','Email','required|trim|valid_email');
            $this->form_validation->set_rules('phone','Phone','required|trim');
            $this->form_validation->set_rules('password','Password','required|trim');
            
            if($this->form_validation->run() == false){
                echo json_encode(array('error'=>'true','errormsg'=>validation_errors()));
            }else{
            
            }
        
        }
                
        private function _provider_exists($provider){
            if($this->contractor_model->provider_exists($provider)){
                return(true);
            }else{
                return(false);
            }
        }    
    }

?>

This function is used as a ajax call, and returns json to my calling javascript function. However even if I access the file directly, I'm still not getting any error output.

Thanks for taking a look!

Greg

El Forum

[eluser]ggoforth[/eluser]
Another wierd thing, the function is returning false, even if all the information is provided and should pass validation. Hmmmmm....

Greg

El Forum

[eluser]David Johansson[/eluser]
[quote author="ggoforth" date="1248419651"]Another wierd thing, the function is returning false, even if all the information is provided and should pass validation. Hmmmmm....

Greg[/quote]
That would've been my 2nd question...

El Forum

[eluser]ggoforth[/eluser]
[quote author="David Johansson" date="1248421249"][quote author="ggoforth" date="1248419651"]Another wierd thing, the function is returning false, even if all the information is provided and should pass validation. Hmmmmm....

Greg[/quote]
That would've been my 2nd question...[/quote]

Yeah, I figured it out....and I'm embarrassed I even posted this Smile. See the original post for my explanation...

El Forum

[eluser]David Johansson[/eluser]
What is the code of the form calling the run_reg() function?

El Forum

[eluser]ggoforth[/eluser]
[quote author="David Johansson" date="1248421401"]What is the code of the form calling the run_reg() function?[/quote]

It was a regular form, but I was hijacking the form submit and sending the query string via ajax. The ajax was firing (jquery), but I had neglected to send the query string as data, so it was just posting nothing to the server. Since none of the fields were submitted, CI had nothing to validate, thus the empty validation_errors().

I realized this when I noticed in Firebug nothing was being posted, even though the ajax was firing.

Greg

El Forum

[eluser]David Johansson[/eluser]
I started to suspect something strange at the other end of the process Tongue
Pages: 1 2