Welcome Guest, Not a member yet? Register   Sign In
a custom callback to check if the value is empty
#7

[eluser]xwero[/eluser]
Instead of adding it to the controller you could extend the Validation library
Code:
class MY_Validation extends CI_Validation
{
    function set_custom_message($field,$rule,$custom)
    {
       $this->validation->error_string = '';
       foreach($this->_error_array as $key => $error)
       {
          
          $fieldname = (in_array($field,$this->_fields)?$this->_fields[$field]:$field;
          
          $default_error = sprintf($this->lang->line($rule),$fieldname);
          
          if($default_error == $error)
          {
              $error = sprintf($this->lang->line($custom),$fieldname);
              $this->validation->error_string .= $this->_error_prefix.$error.$this->_error_suffix;
              if(in_array($field,$this->_fields)
              {
                  $sa_error = $fieldname.'_error';
                  $this->$sa_error = $this->_error_prefix.$error.$this->_error_suffix
              }
          }
          else
          {
             $this->validation->error_string .= $this->_error_prefix.$error.$this->_error_suffix;
          }
       }
    }
}
This function checks if the friendly name is set with the set_fields function and generates an individual error message.

The method should be called in the controller when the validation run method is false.


Messages In This Thread
a custom callback to check if the value is empty - by El Forum - 04-21-2008, 02:41 AM
a custom callback to check if the value is empty - by El Forum - 04-21-2008, 03:12 AM
a custom callback to check if the value is empty - by El Forum - 04-21-2008, 03:23 AM
a custom callback to check if the value is empty - by El Forum - 04-21-2008, 03:58 AM
a custom callback to check if the value is empty - by El Forum - 04-21-2008, 04:11 AM
a custom callback to check if the value is empty - by El Forum - 04-21-2008, 04:15 AM
a custom callback to check if the value is empty - by El Forum - 04-21-2008, 04:59 AM
a custom callback to check if the value is empty - by El Forum - 04-21-2008, 11:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB