Welcome Guest, Not a member yet? Register   Sign In
CI 3 + HMVC form_validation library problem
#1

(This post was last modified: 02-02-2015, 02:08 PM by geekita.)

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.
Reply
#2

(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;

Reply
#3

Where are you loading the form validation library?
Reply
#4

Right before the first set_rules statement.
Reply
#5

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?
Reply
#6

Yes, I tried with no underscore but nothing changed.
Reply
#7

(This post was last modified: 02-01-2015, 06:33 PM by twpmarketing. Edit Reason: additional information )

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.
CI 3.1 Kubuntu 19.04 Apache 5.x  Mysql 5.x PHP 5.x PHP 7.x
Remember: Obfuscation is a bad thing.
Clarity is desirable over Brevity every time.
Reply
#8

(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.
Reply
#9

Are you trying to validate a GET form?
Reply
#10

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

No. It's an Ajax post request.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB