0

How to create custom form validators in MY_Form_validation.php file in HMVC and run them in any module/controller in HMVC structure for validation purpose.

note :- I have no issues in running callback validators working fine no issues.

I want to create some general validators which I can apply on anywhere in project.

Rupesh Terase
  • 440
  • 3
  • 14

1 Answers1

1

you can create library file like this

class MY_Form_validation extends CI_Form_validation
{
    function custom() {

    }
}

and can call this function as you call other validation form function in HMVC

  • Done not working. when i add same function to callback it works but when i add same function to `MY_Form_validation.php` its not working(removed callback_ from function name while calling). – Rupesh Terase Aug 20 '15 at 13:50
  • please check syntax is proper as it may not work with same as callback. –  Aug 20 '15 at 13:55
  • worked thanks. create MY_Form_validation.php file in application/libraries & copy below code for callback and custom validations `class MY_Form_validation extends CI_Form_validation { function run($module = '', $group = '') { (is_object($module)) AND $this->CI =& $module; return parent::run($group); } function custom($abc,$xyz) { if($abc == $xyz) { $this->CI->form_validation->set_message('custom', 'this is working.'); return false; } else { return true; } }` – Rupesh Terase Aug 21 '15 at 06:29