• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
custom validation rule like required (want to use another "required" error msg)

#1
hi .. i extended CI_Form_validation by MY_Form_validation and overrided method run (i just doesnt want to touch system folder):

override changes (just this change):

Code:
//$this->CI->lang->load('form_validation');
$this->CI->lang->load('form_validation', '', FALSE, TRUE, APPPATH);


i wanted to load automatically custom form_validation_lang file in application/languages/english with translations for my custom validation functions in MY_Form_validation
for example function:
Code:
protected function is_valid_parameter_value($value)
       {
               if (($values = $this->CI->config->item($key, 'parameters')) !== NULL)
               {
                       if (in_array($value, $values))
                       {
                               return TRUE;
                       }
               }
               
               return FALSE;
       }

called like core form_validation function rule:

Code:
$this->form_validation->set_rules('currency_dec_point', 'lang:currency_separator', 'trim|required|is_valid_parameter_value[currency.dec_point]');


and in application/languages/english/form_validation_lang i have line
Code:
$lang['form_validation_is_valid_parameter_value'] = "Field {field} contain not allowed value.";

this work perfectly ... however .. i wanted to create equivalent to "required " core rule, function called "required_param" but it seems like i have to define at first required rule for field and then library with use any other rules defined after ... i need make "required_param" work even when is value empty to return custom validation error instead required validation message

thought will do that just like this in MY_Form_validation:
Code:
protected function required_param($value)
       {
               if (!$this->required($value))
               {
                       return FALSE;
               }
               
               return TRUE;
       }

but its not so easy as i expected ... any ideas ? ... thank you
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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