Welcome Guest, Not a member yet? Register   Sign In
Form Validation - returns "(Anonymous function)"
#2

(This post was last modified: 03-13-2018, 07:59 AM by jreklund.)

I haven't tested putting the validation inside a modal. Only in the same libraries. Maybe it can't find the form_validation if it's differs from the file initializing it. But the documentation clearly states that it should work.
I'm doing it like this, querying the modal instead. 

PHP Code:
public function login()
{
 
   $this->load->helper('form');
 
   $this->load->library('form_validation');
 
   
    $validation_rules 
= array(
 
       array(
 
           'field' => 'username',
 
           'label' => lang('login_email'),
 
           'rules' => array(
 
               'trim',
 
               'valid_email'
 
           )
 
       ),
 
       array(
 
           'field' => 'password',
 
           'label' => lang('login_password'),
 
           'rules' => array(
 
               'trim',
 
               'required',
 
               array('validate_auth', array( $this'_validate_auth' ) )
 
           )
 
       )
 
   );
 
   
    $this
->form_validation->set_rules$validation_rules );
 
   
    if
$this->form_validation->run() === TRUE )
 
   {
 
       return TRUE;
 
   }
 
   return FALSE;
}

// --------------------------------------------------------------

public function _validate_auth()
{
 
   $user_email        $this->input->post('username');
 
   $user_password    $this->input->post('password');
 
   
    if
( empty($user_email) OR empty($user_password) )
 
   {
 
       $this->form_validation->set_message('validate_auth'lang('error_missing_fields'));                
        return FALSE
;
 
   }
 
   
    if
$auth_data $this->auth_model->get_auth_data$user_email ) )
 
   {
 
       if$auth_data->banned === '1' )
 
       {
 
           $this->form_validation->set_message('validate_auth'lang('error_username_password'));
 
           return FALSE;
 
       }
 
       if( ! $this->check_password$auth_data->passwd$user_password ) )
 
       {
 
           $this->form_validation->set_message('validate_auth'lang('error_username_password'));
 
       }
 
       else
        
{
 
           // Setup redirection if redirect required
 
           $this->redirect_after_login();
 
                   
            
// Set session cookie and remember me
 
           $this->maintain_state$auth_data );
 
           
            
// Send the auth data back to the controller
 
           return TRUE;
 
       }
 
   }
 
   else
    
{
 
       $this->form_validation->set_message('validate_auth'lang('error_username_password'));
 
   }
 
   
    return FALSE
;


Maybe you need to use CI() on this too:
PHP Code:
$this->form_validation->set_message('check_duplicates''This person already exists!');
$this->ci()->form_validation->set_message('check_duplicates''This person already exists!'); 
Reply


Messages In This Thread
RE: Form Validation - returns "(Anonymous function)" - by jreklund - 03-13-2018, 07:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB