CodeIgniter Forums
Form validation callback not executed when rules are located in config/form_validation.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Form validation callback not executed when rules are located in config/form_validation.php (/showthread.php?tid=56321)



Form validation callback not executed when rules are located in config/form_validation.php - El Forum - 12-10-2012

[eluser]luismartin[/eluser]
I defined all the validation rules in
config/form_validation.php

and this is the rule:

Code:
$config = array(
     // other validation groups.....,
     'articles' => array(
          // other validated fields.....,
          array(
                'field' => 'date_p',
                'label' => 'Publishing date',
                'rules' => 'callback_match_date'
          )
     )
);

Note that I couldn't use a rule like this:

Code:
regex_match[/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20)\d\d$/]

because it generated an error in the preg_match function, and as I've been told, pipes are buggy in CodeIgniter validation rules. So I decided to use the specified callback "match_date", which is implemented this way:

Code:
function mach_date($date) {
        /* DEBUG */ echo 'Here I am!'; exit;
        return (bool)preg_match('/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20)\d\d$/', $date);
    }

I've placed it within the controller in which the form validation is run. But the echo is not being reached.

Any help?


Form validation callback not executed when rules are located in config/form_validation.php - El Forum - 12-10-2012

[eluser]luismartin[/eluser]
It was just a misspelling. I missed the "t" in "mach_date".

The callback actually works within the controller class.