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(-) (limited to 'system') 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