summaryrefslogtreecommitdiffstats
path: root/system/libraries
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-12-14 09:15:30 +0100
committerAndrey Andreev <narf@bofh.bg>2012-12-14 09:15:30 +0100
commit749f2503dc055fa7e1f376af6435f500eb5db0e1 (patch)
tree08c3c677f89d3ad3e4d61404e153a82ebc16cb8b /system/libraries
parent545a7c86701875e1412bcde316e9bcc76d9a23a0 (diff)
parentd6a1902297e336276e85d7f06f3bc58c012bc915 (diff)
Merge pull request #961 from cryode/feature/form_error_msgs
Improved form validation rule error messages.
Diffstat (limited to 'system/libraries')
-rw-r--r--system/libraries/Form_validation.php25
1 files changed, 23 insertions, 2 deletions
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index e4eac04ba..ecd5b18df 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -615,7 +615,7 @@ class CI_Form_validation {
}
// Build the error message
- $message = sprintf($line, $this->_translate_fieldname($row['label']));
+ $message = $this->_build_error_msg($line, $this->_translate_fieldname($row['label']));
// Save the error message
$this->_field_data[$row['field']]['error'] = $message;
@@ -767,7 +767,7 @@ class CI_Form_validation {
}
// Build the error message
- $message = sprintf($line, $this->_translate_fieldname($row['label']), $param);
+ $message = $this->_build_error_msg($line, $this->_translate_fieldname($row['label']), $param);
// Save the error message
$this->_field_data[$row['field']]['error'] = $message;
@@ -807,6 +807,27 @@ class CI_Form_validation {
}
// --------------------------------------------------------------------
+
+ /**
+ * Build an error message using the field and param.
+ *
+ * @param string The error message line
+ * @param string A field's human name
+ * @param mixed A rule's optional parameter
+ * @return string
+ */
+ protected function _build_error_msg($line, $field = '', $param = '')
+ {
+ // Check for %s in the string for legacy support.
+ if (strpos($line, '%s') !== FALSE)
+ {
+ return sprintf($line, $field, $param);
+ }
+
+ return str_replace(array('{field}', '{param}'), array($field, $param), $line);
+ }
+
+ // --------------------------------------------------------------------
/**
* Get the value from a form