Merge pull request #1461 from kwoodfriend/develop
Modified Form Validation class's set_rules()
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 77c968e..6cbe032 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -187,6 +187,12 @@
return $this;
}
+ // Convert an array of rules to a string
+ if (is_array($rules))
+ {
+ $rules = implode('|', $rules);
+ }
+
// No fields? Nothing to do...
if ( ! is_string($field) OR ! is_string($rules) OR $field === '')
{
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index ab3e013..33b4131 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -147,6 +147,7 @@
- _execute() now considers input data to be invalid if a specified rule is not found.
- Removed method is_numeric() as it exists as a native PHP function and _execute() will find and use that (the 'is_numeric' rule itself is deprecated since 1.6.1).
- Native PHP functions used as rules can now accept an additional parameter, other than the data itself.
+ - Updated set_rules() to accept an array of rules as well as a string.
- Changed the :doc:`Session Library <libraries/sessions>` to select only one row when using database sessions.
- Added all_flashdata() method to session class. Returns an associative array of only flashdata.
- Allowed for setting table class defaults in a config file.
diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst
index 3c0e6ed..3bcad7b 100644
--- a/user_guide_src/source/libraries/form_validation.rst
+++ b/user_guide_src/source/libraries/form_validation.rst
@@ -304,6 +304,10 @@
new error messages that correspond to your new rules. There are numerous
rules available which you can read about in the validation reference.
+.. note:: You can also pass an array of rules to set_rules(), instead of a string. Example::
+
+ $this->form_validation->set_rules('username', 'Username', array('required', 'min_length[5]'));
+
Prepping Data
=============
@@ -935,7 +939,7 @@
:param string $field: The field name
:param string $label: The field label
- :param string $rules: The rules, seperated by a pipe "|"
+ :param mixed $rules: The rules, as a string with rules separated by a pipe "|", or an array or rules.
:rtype: Object
Permits you to set validation rules, as described in the tutorial