• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form validation callbacks not working

#1
Hello,

After upgrade from 2.2.6 to 3.1.9. I noticed my callback function for form validation not working.

PHP Code:
function update_password()
    {
        
        if(
$this->session->userdata('recovery')!='yes')
        
$this->form_validation->set_rules('current_password''Current Password''callback_currentpass_check');
        
        
$this->form_validation->set_rules('new_password''New Password''required|matches[re_password]');
        
$this->form_validation->set_rules('re_password''Password Confirmation''required');
            
        if (
$this->form_validation->run() == FALSE)
        {
            
$this->changepass();    
        }
        else
        {
            
                
$password $this->input->post('new_password');
                
$this->auth_model->update_password($password);
                
$this->session->set_userdata('recovery',"no");
                
$this->session->set_flashdata('msg''<div class="alert alert-success">Password changed successfully</div>');                
            
            
redirect(site_url('admin/auth/changepass'));        
        }
    
    } 



PHP Code:
public function currentpass_check($str)
    {
        
$user_name 'test_user';
        
$res $this->auth_model->check_login($user_name,$str);
        
        if (
$res == 0)
        {
            
$this->form_validation->set_message('currentpass_check''Current password Didn\'t match');
            return 
FALSE;
        }
        else
        {
            return 
TRUE;
            
        }
    } 

I am getting this error.
[Image: 50575236-2500a200-0e03-11e9-97ae-d19325f4aa60.png]
My callback function ( currentpass_check) returns TRUE.
English only; no SEO spam
Reply

#2
Instead of 
PHP Code:
$this->form_validation->set_message('currentpass_check''Current password Didn\'t match'); 
try this:

PHP Code:
$this->form_validation->set_message('current_password''Current password Didn\'t match'); 

untested...
Reply

#3
@codehoster,

...or simply try using the double quotes.


PHP Code:
$this->form_validation->set_message('current_password'"Current password Didn't match"); 
Reply

#4
(01-02-2019, 11:34 AM)Codinglander Wrote: Instead of 
PHP Code:
$this->form_validation->set_message('currentpass_check''Current password Didn\'t match'); 
try this:

PHP Code:
$this->form_validation->set_message('current_password''Current password Didn\'t match'); 

untested...

Same error!

https://www.codeigniter.com/userguide3/l...ation.html

In documentation your recommendation is not valid.


Attached Files Thumbnail(s)
   
English only; no SEO spam
Reply

#5
Try changing it to this:

PHP Code:
$this->form_validation->set_message('current_password''Current password do not match'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#6
Are you absolutely sure that it returns TRUE? It dosen't need to access a message in case it's TRUE, only on FALSE.
Are these function placed in the same .php file or are you extending it?
Reply

#7
Yes I am absolutely sure!
Reply

#8
@Codehoster,

Did you try the double quotes? Just wondering?
Reply

#9
The set_message method allows you to set your own error messages on the fly. But one thing you should notice is that the key name has to match the function name that it corresponds to.

If you need to modify your custom rule, which is _check_valid_username, you can do so by perform set_message within this function:

function _check_valid_username($str)
{
// Your validation code
// ...
// Put this in condition where you want to return FALSE
$this->form_validation->set_message('_check_valid_username', 'Error Message');
//
}
If you want to change the default error message for a specific rule, you can do so by invoking set_message with the first parameter as the rule name and the second parameter as your custom error. E.g., if you want to change the required error :

$this->form_validation->set_message('required', 'Oops this %s is required');
If by any chance you need to change the language instead of the error statement itself, create your own form_validation_lang.php and put it into the proper language folder inside your system language directory.
I will not SEO spam!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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