CodeIgniter Forums
CI 3 + HMVC form_validation library problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: CI 3 + HMVC form_validation library problem (/showthread.php?tid=964)



CI 3 + HMVC form_validation library problem - geekita - 02-01-2015

I have this couple of rules

PHP Code:
$this->form_validation->set_rules('password''New Password''callback__check_password');
$this->form_validation->set_rules('confirm_password''Confirm new password''matches[password]');

...

public function 
_check_password($password) {
    $result = empty($password) || (strlen($password) >= 10);

    if ($result === FALSE) {
        $this->form_validation->set_message('_check_password''MESSAGE ERROR');
    }

    return $result;


and I receive this message on form submit: 'Unable to access an error message corresponding to your field name New Password.'
Even if I use a callback like this

PHP Code:
public function _check_password($password) {
 
   $this->form_validation->set_message('_check_password''MESSAGE ERROR');

 
   return TRUE // or FALSE;


I get same error.


RE: CI 3 form_validation library problem - egall8 - 02-01-2015

(02-01-2015, 11:09 AM)geekita Wrote: I have this couple of rules



PHP Code:
$this->form_validation->set_rules('password''New Password''callback__check_password');
$this->form_validation->set_rules('confirm_password''Confirm new password''matches[password]');

...

public function 
_check_password($password) {
    $result = empty($password) || (strlen($password) >= 10);

    if ($result === FALSE) {
        $this->form_validation->set_message('_check_password''MESSAGE ERROR');
    }

    return $result;


and I receive this message on form submit: 'Unable to access an error message corresponding to your field name New Password.'
Even if I use a callback like this



PHP Code:
public function _check_password($password) {
 
   $this->form_validation->set_message('_check_password''MESSAGE ERROR');

 
   return TRUE // or FALSE;


I get same error.

Where you set the message in your callback, the first var should be the rule name (password). Right now you are setting the message for the rule _check_password, which is the name of the callback not the actual rule.

PHP Code:
public function _check_password($password) {
    
$result = empty($password) || (strlen($password) >= 10);

    if (
$result === FALSE) {
        
$this->form_validation->set_message('password''MESSAGE ERROR');
    }

    return 
$result;




RE: CI 3 form_validation library problem - CroNiX - 02-01-2015

Where are you loading the form validation library?


RE: CI 3 form_validation library problem - geekita - 02-01-2015

Right before the first set_rules statement.


RE: CI 3 form_validation library problem - Avenirer - 02-01-2015

Did you try to name it callback_check_password and the method, if you are scared of any interference, make the method "private function check_password()"? Maybe there is a problem with the underscore?


RE: CI 3 form_validation library problem - geekita - 02-01-2015

Yes, I tried with no underscore but nothing changed.


RE: CI 3 form_validation library problem - twpmarketing - 02-01-2015

You have a double underscore in the validation rule function name:
[quote pid='4456' dateline='1422814140']

Code:
$this->form_validation->set_rules('password', 'New Password', 'callback__check_password');

[/quote]

Try using only one underscore and the function should have no leading underscore in its declaration

Your use of an underscore in the method name may be invoking the legacy code for a private function:
From the CI 3.0 docs:
CodeIgniter-3.0rc/user_guide/general/controllers.html#private-methods

Quote:Prefixing method names with an underscore will also prevent them from being called. This is a legacy feature that is left for backwards-compatibility.



RE: CI 3 form_validation library problem - geekita - 02-02-2015

(02-01-2015, 06:08 PM)twpmarketing Wrote: You have a double underscore in the validation rule function name:

[quote pid='4456' dateline='1422814140']

Code:
$this->form_validation->set_rules('password', 'New Password', 'callback__check_password');

Try using only one underscore and the function should have no leading underscore in its declaration

Your use of an underscore in the method name may be invoking the legacy code for a private function:
From the CI 3.0 docs:
CodeIgniter-3.0rc/user_guide/general/controllers.html#private-methods


Quote:Prefixing method names with an underscore will also prevent them from being called. This is a legacy feature that is left for backwards-compatibility.

[/quote]

Yes, I tried with no underscore but nothing changed.


RE: CI 3 form_validation library problem - Narf - 02-02-2015

Are you trying to validate a GET form?


RE: CI 3 form_validation library problem - geekita - 02-02-2015

(02-02-2015, 07:39 AM)Narf Wrote: Are you trying to validate a GET form?

No. It's an Ajax post request.