summaryrefslogtreecommitdiffstats
path: root/system/libraries
diff options
context:
space:
mode:
authorSai Phaninder Reddy Jonnala <sai.jonnala@gopassport.com>2015-12-28 21:19:31 +0100
committerSai Phaninder Reddy Jonnala <sai.jonnala@gopassport.com>2015-12-28 21:19:31 +0100
commitf3b711fd9f7d8e096bf774f9c6cfc0a4ca075919 (patch)
treef0a03e933a26c84aa2e9751373ea47b392a94da8 /system/libraries
parent78b151646f4fb684c0328a67cb2a9bed3e1d8f3f (diff)
Refactor: logic to get the rule's error message
Diffstat (limited to 'system/libraries')
-rw-r--r--system/libraries/Form_validation.php73
1 files changed, 43 insertions, 30 deletions
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index c2212585d..12cfdff43 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -637,21 +637,7 @@ class CI_Form_validation {
// Set the message type
$type = in_array('required', $rules) ? 'required' : 'isset';
- // Check if a custom message is defined
- if (isset($this->_field_data[$row['field']]['errors'][$type]))
- {
- $line = $this->_field_data[$row['field']]['errors'][$type];
- }
- elseif (isset($this->_error_messages[$type]))
- {
- $line = $this->_error_messages[$type];
- }
- elseif (FALSE === ($line = $this->CI->lang->line('form_validation_'.$type))
- // DEPRECATED support for non-prefixed keys
- && FALSE === ($line = $this->CI->lang->line($type, FALSE)))
- {
- $line = 'The field was not set';
- }
+ $line = $this->_get_raw_error_message($type, $row);
// Build the error message
$message = $this->_build_error_msg($line, $this->_translate_fieldname($row['label']));
@@ -820,23 +806,9 @@ class CI_Form_validation {
{
$line = $this->CI->lang->line('form_validation_error_message_not_set').'(Anonymous function)';
}
- // Check if a custom message is defined
- elseif (isset($this->_field_data[$row['field']]['errors'][$rule]))
- {
- $line = $this->_field_data[$row['field']]['errors'][$rule];
- }
- elseif ( ! isset($this->_error_messages[$rule]))
- {
- if (FALSE === ($line = $this->CI->lang->line('form_validation_'.$rule))
- // DEPRECATED support for non-prefixed keys
- && FALSE === ($line = $this->CI->lang->line($rule, FALSE)))
- {
- $line = $this->CI->lang->line('form_validation_error_message_not_set').'('.$rule.')';
- }
- }
else
{
- $line = $this->_error_messages[$rule];
+ $line = $this->_get_raw_error_message($rule, $row);
}
// Is the parameter we are inserting into the error message the name
@@ -865,6 +837,47 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
+ * Get the error message for the rule
+ *
+ * @param string the rule name.
+ * @param array
+ * @return string
+ */
+ private function _get_raw_error_message($key, $row)
+ {
+ $error_message = '';
+ // Check if a custom message is defined through validation config row.
+ if (isset($this->_field_data[$row['field']]['errors'][$key]))
+ {
+ $error_message = $this->_field_data[$row['field']]['errors'][$key];
+ }
+ // check if a custom message has been set using the set_message() function
+ elseif (isset($this->_error_messages[$key]))
+ {
+ $error_message = $this->_error_messages[$key];
+ }
+ // check if we have an error message in lang file
+ elseif (FALSE !== ($line_tmp = $this->CI->lang->line('form_validation_'.$key)))
+ {
+ $error_message = $line_tmp;
+ }
+ // DEPRECATED support for non-prefixed keys, lang file again
+ elseif (FALSE !== ($line_tmp = $this->CI->lang->line($key, FALSE)))
+ {
+ $error_message = $line_tmp;
+ }
+ //error message not found
+ else
+ {
+ $error_message = $this->CI->lang->line('form_validation_error_message_not_set').'('.$key.')';
+ }
+
+ return $error_message;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Translate a field name
*
* @param string the field name