summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/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 /user_guide_src/source/libraries
parentefe33a2187ceb501e3c2038016c89f8423b8bcaa (diff)
Add 'named callable' rules to Form validation library
Requested in issue #3183 Supersedes PR #3220
Diffstat (limited to 'user_guide_src/source/libraries')
-rw-r--r--user_guide_src/source/libraries/form_validation.rst31
1 files changed, 30 insertions, 1 deletions
diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst
index 2ae56d29a..2b7780ff2 100644
--- a/user_guide_src/source/libraries/form_validation.rst
+++ b/user_guide_src/source/libraries/form_validation.rst
@@ -505,11 +505,40 @@ function::
'required',
function($value)
{
- // Check $value and return TRUE/FALSE
+ // Check $value
}
)
);
+Of course, since a Callable rule by itself is not a string, it isn't
+a rule name either. That is a problem when you want to set error messages
+for them. In order to get around that problem, you can put such rules as
+the second element of an array, with the first one being the rule name::
+
+ $this->form_validation->set_rules(
+ 'username', 'Username',
+ array(
+ 'required',
+ array('username_callable', array($this->users_model', 'valid_username'))
+ )
+ );
+
+Anonymous function (PHP 5.3+) version::
+
+ $this->form_validation->set_rules(
+ 'username', 'Username',
+ array(
+ 'required',
+ array(
+ 'username_callable',
+ function($str)
+ {
+ // Check validity of $str and return TRUE or FALSE
+ }
+ )
+ )
+ );
+
.. _setting-error-messages:
Setting Error Messages