• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form Validation Callback Not Working on Server (but OK on WAMP)

#1
Hi all,

I've developed a CI site on my local machine using WAMP. I'm using CI 3 with the HMVC extension and it all works fine.

I've just uploaded the site to the production server and changed the config files etc to get it working. However, form validation callbacks are not working on the production server.

Here's an example from a login form:

PHP Code:
// Process login form
        public function submit()
        {
            $this->load->library('form_validation');
            $username $this->input->post('username'TRUE);
            $this->form_validation->set_rules('username''Username''required');
            $this->form_validation->set_rules('password''Password''required|callback_do_login');
            
            
if($this->form_validation->run($this) == FALSE)
            {
                $this->login();
            }
            else 
            {
                // Set login session
                
                
...
            }
        


This is the callback function do_login:

PHP Code:
public function do_login($password)
        {
            
            
// Get user / pass from POST
            $submitted_password $this->input->post('password'TRUE);
            $username $this->input->post('username'TRUE);
            
            $this
->crud->setTable($this->table);
            $this->load->model('mdl_users');
            
            
// Check User Exists
            $query $this->mdl_users->getUser($username);
            if($query->num_rows() == 1)
            {
                // Get stored password
                $row $query->row();
                $stored_password $row->password;
                
                
// Check password
                $this->load->module('mod_security');
                $result $this->mod_security->login($username$submitted_password$stored_password); // Returns false if no match
                
                
return ($result) ? TRUE FALSE;
            }
            else
            {
                
                
return FALSE;
            }
            
        



On my local WAMP setup, this all works fine. But on the server
PHP Code:
$this->form_validation->run($this
always returns false.

To eliminate any errors with the callback function itself, I changed it to the following as a test:

PHP Code:
public function do_login($password)
{
 
     return TRUE;


... which will obviously always return TRUE, however when $this->form_validation->run($this) is called, even though I changed the do_login callback function to return TRUE, $this->form_validation->run($this) still returns FALSE!!

This is driving me crazy and I have no idea why this is happening. It is as if the form validation is ignoring the callback function and just returning false.

Can anyone help me? Could it be a setting on the server causing it or something else that could have changed when I uploaded the site files to the server?

If it is relevant, on my local machine, within the do_login callback function I had originally set the callback error message like this:


PHP Code:
$this->form_validation->set_message('do_login''User / Pass Incorrect'); 


...which worked fine, but on the production server it threw an error stating:  "Unable to access an error message corresponding to your field name Password.(do_login)".  I had to set the error message in the language file to overcome this. But the fact that this happen on the production server and not on my WAMP setup makes me think there must be some setting or something on the server that is causing this.

Anyway, any help is gratefully received.

Thanks
Reply


Messages In This Thread
Form Validation Callback Not Working on Server (but OK on WAMP) - by 50cent - 03-18-2016, 06:23 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.