From 60858b65a4be78b1d384492588b52e98fd644403 Mon Sep 17 00:00:00 2001 From: zoaked Date: Sun, 20 Sep 2015 17:16:24 -0400 Subject: Persist config file settings when resetting form_validation When checking multiple arrays using form_validation you have to call reset_validation between each separate check due to the instance of the library being a singleton. The issue comes in when the settings are loaded from a config file as they are initially loaded from a parameter in the constructor, but are set to an empty array when resetting the class. To get around this issue a copy of the config parameter is made and then the copy is used to reset the rules when clearing. --- system/libraries/Form_validation.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index af90316a4..a2991395c 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -68,6 +68,7 @@ class CI_Form_validation { * @var array */ protected $_config_rules = array(); + private $_default_config_rules = array(); /** * Array of validation errors @@ -141,7 +142,7 @@ class CI_Form_validation { } // Validation rules can be stored in a config file. - $this->_config_rules = $rules; + $this->_default_config_rules = $this->_config_rules = $rules; // Automatically load the form helper $this->CI->load->helper('form'); @@ -1586,7 +1587,7 @@ class CI_Form_validation { public function reset_validation() { $this->_field_data = array(); - $this->_config_rules = array(); + $this->_config_rules = $this->_default_config_rules; $this->_error_array = array(); $this->_error_messages = array(); $this->error_string = ''; -- cgit v1.2.3-24-g4f1b From f1ca7661ed6479a0f53b20ec5e704321b3e47fcf Mon Sep 17 00:00:00 2001 From: zoaked Date: Sun, 20 Sep 2015 22:29:13 -0400 Subject: Switch from saving copy of config to reset method parameter --- system/libraries/Form_validation.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index a2991395c..aca1d1da9 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -68,7 +68,6 @@ class CI_Form_validation { * @var array */ protected $_config_rules = array(); - private $_default_config_rules = array(); /** * Array of validation errors @@ -142,7 +141,7 @@ class CI_Form_validation { } // Validation rules can be stored in a config file. - $this->_default_config_rules = $this->_config_rules = $rules; + $this->_config_rules = $rules; // Automatically load the form helper $this->CI->load->helper('form'); @@ -1582,12 +1581,14 @@ class CI_Form_validation { * Prevents subsequent validation routines from being affected by the * results of any previous validation routine due to the CI singleton. * + * @param bool * @return CI_Form_validation */ - public function reset_validation() + public function reset_validation($keep_config=false) { $this->_field_data = array(); - $this->_config_rules = $this->_default_config_rules; + if( ! $keep_config) + $this->_config_rules = array(); $this->_error_array = array(); $this->_error_messages = array(); $this->error_string = ''; -- cgit v1.2.3-24-g4f1b From 16742b2bc7183e0b74c02532f8bbceed191fa4e2 Mon Sep 17 00:00:00 2001 From: zoaked Date: Sun, 20 Sep 2015 22:37:05 -0400 Subject: Update changelog.rst --- user_guide_src/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 64120df8e..0448025cc 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -22,6 +22,7 @@ Bug fixes for 3.0.2 - Fixed a bug (#2284) - :doc:`Database ` method ``protect_identifiers()`` breaks when :doc:`Query Builder ` isn't enabled. - Fixed a bug (#4052) - :doc:`Routing ` with anonymous functions didn't work for routes that don't use regular expressions. +- Fixed a bug (#4126) - Added optional parameter to ``reset_validation()`` in ``Form_validation`` that stops ``_config_rules`` from being cleared. Version 3.0.1 ============= -- cgit v1.2.3-24-g4f1b From 3fa8486605da66f5436d44cac16279233bb0cf47 Mon Sep 17 00:00:00 2001 From: zoaked Date: Sun, 20 Sep 2015 22:55:35 -0400 Subject: Update form_validation.rst --- user_guide_src/source/libraries/form_validation.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index be6d1f233..858ff1ac0 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -714,6 +714,8 @@ file. You can organize these rules into "groups". These groups can either be loaded automatically when a matching controller/method is called, or you can manually call each set as needed. +.. important:: Make sure that when using the ``reset_validation()`` method you pass ``true`` as a parameter. If you do not then all the validation rules loaded from the config file will be cleared as well! + How to save your rules ====================== @@ -1076,8 +1078,9 @@ Class Reference Permits you to set an array for validation, instead of using the default ``$_POST`` array. - .. php:method:: reset_validation() + .. php:method:: reset_validation($keep_config=false) + :param bool $keep_config: Will leave configured validation rules alone when true or clear them when false. This parameter must be true if your rules are being loaded from a config file :returns: CI_Form_validation instance (method chaining) :rtype: CI_Form_validation @@ -1137,4 +1140,4 @@ the following functions: - :php:func:`set_radio()` Note that these are procedural functions, so they **do not** require you -to prepend them with ``$this->form_validation``. \ No newline at end of file +to prepend them with ``$this->form_validation``. -- cgit v1.2.3-24-g4f1b From cf0586148b4a2901adc21575fb9487f9aeaa6892 Mon Sep 17 00:00:00 2001 From: zoaked Date: Mon, 21 Sep 2015 22:41:07 -0400 Subject: Styling changes --- system/libraries/Form_validation.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index aca1d1da9..31f80e959 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1584,14 +1584,16 @@ class CI_Form_validation { * @param bool * @return CI_Form_validation */ - public function reset_validation($keep_config=false) + public function reset_validation($keep_config = FALSE) { $this->_field_data = array(); - if( ! $keep_config) - $this->_config_rules = array(); $this->_error_array = array(); $this->_error_messages = array(); $this->error_string = ''; + if ( ! $keep_config) + { + $this->_config_rules = array(); + } return $this; } -- cgit v1.2.3-24-g4f1b From 2811b5554e9a348a35873bf3b867d8e2773d2728 Mon Sep 17 00:00:00 2001 From: zoaked Date: Mon, 21 Sep 2015 22:47:52 -0400 Subject: Added optional parameter to reset_validation() in form_validation library --- user_guide_src/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 0448025cc..e176f4355 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -16,13 +16,13 @@ Release Date: Not Released - General Changes - Updated the *application/config/constants.php* file to check if constants aren't already defined before doing that. + - Added optional parameter to ``reset_validation()`` in :doc:`form validation` that stops ``_config_rules`` from being cleared. Bug fixes for 3.0.2 ------------------- - Fixed a bug (#2284) - :doc:`Database ` method ``protect_identifiers()`` breaks when :doc:`Query Builder ` isn't enabled. - Fixed a bug (#4052) - :doc:`Routing ` with anonymous functions didn't work for routes that don't use regular expressions. -- Fixed a bug (#4126) - Added optional parameter to ``reset_validation()`` in ``Form_validation`` that stops ``_config_rules`` from being cleared. Version 3.0.1 ============= -- cgit v1.2.3-24-g4f1b From 505e15d01bb4b1b222d9685062d5c294c1ad38c0 Mon Sep 17 00:00:00 2001 From: zoaked Date: Mon, 21 Sep 2015 23:02:30 -0400 Subject: Added optional parameter to reset_validation() --- user_guide_src/source/libraries/form_validation.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index 858ff1ac0..15d9b1cb7 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -714,8 +714,6 @@ file. You can organize these rules into "groups". These groups can either be loaded automatically when a matching controller/method is called, or you can manually call each set as needed. -.. important:: Make sure that when using the ``reset_validation()`` method you pass ``true`` as a parameter. If you do not then all the validation rules loaded from the config file will be cleared as well! - How to save your rules ====================== @@ -1078,9 +1076,9 @@ Class Reference Permits you to set an array for validation, instead of using the default ``$_POST`` array. - .. php:method:: reset_validation($keep_config=false) + .. php:method:: reset_validation($keep_config = FALSE) - :param bool $keep_config: Will leave configured validation rules alone when true or clear them when false. This parameter must be true if your rules are being loaded from a config file + :param bool $keep_config: Whether to reset validation rules from config files :returns: CI_Form_validation instance (method chaining) :rtype: CI_Form_validation -- cgit v1.2.3-24-g4f1b From bbed8d5429917d5f7b188bcf59d9156e330a7749 Mon Sep 17 00:00:00 2001 From: zoaked Date: Sat, 26 Sep 2015 12:40:31 -0400 Subject: Removing config_rules from reset_validation Signed-off-by: Junior Asparagus --- system/libraries/Form_validation.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 31f80e959..a158225ee 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1581,19 +1581,14 @@ class CI_Form_validation { * Prevents subsequent validation routines from being affected by the * results of any previous validation routine due to the CI singleton. * - * @param bool * @return CI_Form_validation */ - public function reset_validation($keep_config = FALSE) + public function reset_validation() { $this->_field_data = array(); $this->_error_array = array(); $this->_error_messages = array(); $this->error_string = ''; - if ( ! $keep_config) - { - $this->_config_rules = array(); - } return $this; } -- cgit v1.2.3-24-g4f1b From 8ccab5218d318ce14ad3a7d76477a21a8930e269 Mon Sep 17 00:00:00 2001 From: zoaked Date: Sat, 26 Sep 2015 12:44:10 -0400 Subject: Removed reset_validation changes that were no longer needed --- user_guide_src/source/libraries/form_validation.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index 15d9b1cb7..140bbc65d 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -1076,9 +1076,8 @@ Class Reference Permits you to set an array for validation, instead of using the default ``$_POST`` array. - .. php:method:: reset_validation($keep_config = FALSE) + .. php:method:: reset_validation() - :param bool $keep_config: Whether to reset validation rules from config files :returns: CI_Form_validation instance (method chaining) :rtype: CI_Form_validation -- cgit v1.2.3-24-g4f1b From c8f30aac973491cb6a00335c8ac768c149245e11 Mon Sep 17 00:00:00 2001 From: zoaked Date: Sat, 26 Sep 2015 12:52:11 -0400 Subject: Removing config_rules from reset_validation Signed-off-by: Junior Asparagus --- user_guide_src/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index e176f4355..aa61a886e 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -16,13 +16,13 @@ Release Date: Not Released - General Changes - Updated the *application/config/constants.php* file to check if constants aren't already defined before doing that. - - Added optional parameter to ``reset_validation()`` in :doc:`form validation` that stops ``_config_rules`` from being cleared. Bug fixes for 3.0.2 ------------------- - Fixed a bug (#2284) - :doc:`Database ` method ``protect_identifiers()`` breaks when :doc:`Query Builder ` isn't enabled. - Fixed a bug (#4052) - :doc:`Routing ` with anonymous functions didn't work for routes that don't use regular expressions. +- Fixed a bug (#4126) - :doc:`Form Validation Library ` was needlessly clearing ``$_config_rules`` when calling ``reset_validation()`` method. Version 3.0.1 ============= -- cgit v1.2.3-24-g4f1b From 0dbd848dbc69b74489f1fb4e360e8be785727c76 Mon Sep 17 00:00:00 2001 From: zoaked Date: Mon, 28 Sep 2015 11:38:16 -0400 Subject: Update changelog.rst --- user_guide_src/source/changelog.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index aa61a886e..64120df8e 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -22,7 +22,6 @@ Bug fixes for 3.0.2 - Fixed a bug (#2284) - :doc:`Database ` method ``protect_identifiers()`` breaks when :doc:`Query Builder ` isn't enabled. - Fixed a bug (#4052) - :doc:`Routing ` with anonymous functions didn't work for routes that don't use regular expressions. -- Fixed a bug (#4126) - :doc:`Form Validation Library ` was needlessly clearing ``$_config_rules`` when calling ``reset_validation()`` method. Version 3.0.1 ============= -- cgit v1.2.3-24-g4f1b