• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I put form callbacks in a helper file?

#5
[eluser]CroNiX[/eluser]
Why don't you just extend CI's validation library with your own rules?

/application/libraries/MY_Form_validation.php
Code:
class MY_Form_validation extends CI_Form_validation {
  function __construct()
  {
    parent::__construct():
  }

  // don't need to user underscore to make private since its
  // in the library now and not your controller
  function Valid_Date_Format($date)
  {
    $converted=str_replace('/','-',$date);

    if(preg_match("/^((((19|20)(([02468][048])|([13579][26]))-02-29))|((20[0-9][0-9])|(19[0-9][0-9]))-((((0[1-9])|(1[0-2]))-((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((0[1,3-9])|(1[0-2]))-(29|30)))))$/",$converted)===1)
    {
      return TRUE;
    }
    // Don't need to reference the form_validation object since that is now $this
    $this->set_message('Valid_Date_Format', 'The Date entered is invalid.');
    return FALSE;
  }  
}

Now when setting your rules, you just use the rule name "as is" like the native rules
instead of "callback_rule_name".
Code:
$this->form_validation->set_rules('field', 'Field', 'required|Valid_Date_Format');


Messages In This Thread
How do I put form callbacks in a helper file? - by El Forum - 03-07-2012, 04:31 AM
How do I put form callbacks in a helper file? - by El Forum - 03-07-2012, 07:03 AM
How do I put form callbacks in a helper file? - by El Forum - 03-07-2012, 07:17 AM
How do I put form callbacks in a helper file? - by El Forum - 03-07-2012, 09:00 AM
How do I put form callbacks in a helper file? - by El Forum - 03-07-2012, 10:22 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.