Welcome Guest, Not a member yet? Register   Sign In
Form Validation Callback
#1

(This post was last modified: 04-10-2017, 03:31 AM by RBX.)

I'm using CI 3.1.4, and Validation library can't seem to find my callback function, which goes something like this.

PHP Code:
$this->fv->set_rules('currentPassword''Current Password''required|callback__verifyPassword');

public function 
_verifyPassword($suppliedPassword)
{
 
   $this->fv->set_message(__METHOD__'Incorrect {$field}');
 
   $currentPassword $this->db
        
->select('password')
 
       ->where('id'$this->userData['id'])
 
       ->get(Table::ADMINS)->row()->password;
 
   return $this->AuthModel->passwordVerify($suppliedPassword$currentPassword);


It doesn't matter what I put in the callback function. I always get this:
Quote:Unable to access an error message corresponding to your field name Current Password.(_verifyPassword)

I've tried various names for callback method, but it's of no use. Also, I believe callback function should be called only after the first rule, required fails, but I always see this error message, and nothing about the field being required. If, however, I change callback__verifyPassword to just _verifyPassword, I get error only when I enter something, and error message corresponding to required otherwise.

EDIT:
I get an error message if I define this:
PHP Code:
$lang['_verifyPassword'] = 'Incorrect Password'
but I believe the callback function isn't still called.

EDIT:
I just had a look at CI_Form_validation, and contrary to what I always thought, the validation functions are reordered, and callbacks are always executed.
PHP Code:
    /**
     * Prepare rules
     *
     * Re-orders the provided rules in order of importance, so that
     * they can easily be executed later without weird checks ...
     *
     * "Callbacks" are given the highest priority (always called),
     * followed by 'required' (called if callbacks didn't fail),
     * and then every next rule depends on the previous one passing.
     *
     * @param    array    $rules
     * @return    array
     */ 
Has this changed for previous versions? I can't seem to find anything about this in the documentation. It'd be great if such behavior can be documented.

EDIT:
Sorry for so many edits. I think this is because of the HMVC module I use.
On CI_Form_validation, line 715, it is checked if method exists in $this->CI
PHP Code:
if ( ! method_exists($this->CI$rule)) 
When extending form CI_Controller, this returns true, and when extending from MX_Controller, this returns false.
Reply


Messages In This Thread
Form Validation Callback - by RBX - 04-10-2017, 01:29 AM
RE: Form Validation Callback - by InsiteFX - 04-10-2017, 03:51 AM
RE: Form Validation Callback - by salain - 04-10-2017, 03:53 AM
RE: Form Validation Callback - by InsiteFX - 04-10-2017, 08:52 AM
RE: Form Validation Callback - by RBX - 04-10-2017, 11:02 AM
RE: Form Validation Callback - by Paradinight - 04-10-2017, 11:16 AM
RE: Form Validation Callback - by salain - 04-11-2017, 12:01 AM
RE: Form Validation Callback - by RBX - 04-11-2017, 08:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB