summaryrefslogtreecommitdiffstats
path: root/system/libraries
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-09-08 10:31:48 +0200
committerAndrey Andreev <narf@devilix.net>2014-09-08 10:31:48 +0200
commit60726ef7dc7a70a41a6a8944525d25c4476edea9 (patch)
treebd0f3be4f375ecd4c4ff67e3c6480f313da1e82d /system/libraries
parentefe33a2187ceb501e3c2038016c89f8423b8bcaa (diff)
Add 'named callable' rules to Form validation library
Requested in issue #3183 Supersedes PR #3220
Diffstat (limited to 'system/libraries')
-rw-r--r--system/libraries/Form_validation.php20
1 files changed, 16 insertions, 4 deletions
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 1d654d9f7..b640f1ec1 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -701,6 +701,12 @@ class CI_Form_validation {
{
$callable = TRUE;
}
+ elseif (is_array($rule) && isset($rule[0], $rule[1]) && is_callable($rule[1]))
+ {
+ // We have a "named" callable, so save the name
+ $callable = $rule[0];
+ $rule = $rule[1];
+ }
// Strip the parameter (if exists) from the rule
// Rules can contain a parameter: max_length[5]
@@ -712,7 +718,7 @@ class CI_Form_validation {
}
// Call the function that corresponds to the rule
- if ($callback OR $callable)
+ if ($callback OR $callable !== FALSE)
{
if ($callback)
{
@@ -730,8 +736,14 @@ class CI_Form_validation {
else
{
$result = is_array($rule)
- ? $rule[0]->{$rule[1]}($postdata, $param)
- : $rule($postdata, $param);
+ ? $rule[0]->{$rule[1]}($postdata)
+ : $rule($postdata);
+
+ // Is $callable set to a rule name?
+ if ($callable !== FALSE)
+ {
+ $rule = $callable;
+ }
}
// Re-assign the result to the master data array
@@ -791,7 +803,7 @@ class CI_Form_validation {
// Did the rule test negatively? If so, grab the error.
if ($result === FALSE)
{
- // Callable rules don't have named error messages
+ // Callable rules might not have named error messages
if ( ! is_string($rule))
{
return;