summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2013-03-26 14:44:12 +0100
committerAndrey Andreev <narf@bofh.bg>2013-03-26 14:44:12 +0100
commit5269c1cf2d5ae749309b06194f0a2a737a9ff114 (patch)
treef4155535f7293524b4cdc2c03e4f10369b9263e7 /system
parentee34b84be6697bd4da411edaf625ed97a9480def (diff)
parent408cbb4f3582ac64bb534a6539370992071d5950 (diff)
Merge pull request #2348 from nisheeth-barthwal/feature/nested_keys
Added Parsing Capabilities to Input class for nested array keys
Diffstat (limited to 'system')
-rw-r--r--system/core/Input.php32
-rw-r--r--system/helpers/form_helper.php13
-rw-r--r--system/libraries/Form_validation.php15
3 files changed, 48 insertions, 12 deletions
diff --git a/system/core/Input.php b/system/core/Input.php
index 8d491e055..6690b7f2e 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -153,17 +153,39 @@ class CI_Input {
*/
protected function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
{
- if ( ! isset($array[$index]))
+ if (isset($array[$index]))
{
- return NULL;
+ $value = $array[$index];
}
+ elseif (($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1) // Does the index contain array notation
+ {
+ $value = $array;
+ for ($i = 0; $i < $count; $i++)
+ {
+ $key = trim($matches[0][$i], '[]');
+ if ($key === '') // Empty notation will return the value as array
+ {
+ break;
+ }
- if ($xss_clean === TRUE)
+ if (isset($value[$key]))
+ {
+ $value = $value[$key];
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+ }
+ else
{
- return $this->security->xss_clean($array[$index]);
+ return NULL;
}
- return $array[$index];
+ return ($xss_clean === TRUE)
+ ? $this->security->xss_clean($value)
+ : $value;
}
// --------------------------------------------------------------------
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index fd9e7be7c..2002d4269 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -641,14 +641,13 @@ if ( ! function_exists('set_value'))
*/
function set_value($field = '', $default = '', $is_textarea = FALSE)
{
- if (FALSE === ($OBJ =& _get_validation_object()))
- {
- return isset($_POST[$field])
- ? form_prep($_POST[$field], $is_textarea)
- : form_prep($default, $is_textarea);
- }
+ $CI =& get_instance();
+
+ $value = (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field))
+ ? $CI->form_validation->set_value($field, $default)
+ : $CI->input->post($field, FALSE);
- return form_prep($OBJ->set_value($field, $default), $is_textarea);
+ return form_prep($value === NULL ? $default : $value, $is_textarea);
}
}
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 172e799f6..1ed50844c 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -836,6 +836,21 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
+ * Checks if the rule is present within the validator
+ *
+ * Permits you to check if a rule is present within the validator
+ *
+ * @param string the field name
+ * @return bool
+ */
+ public function has_rule($field)
+ {
+ return isset($this->_field_data[$field]);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Get the value from a form
*
* Permits you to repopulate a form field with the value it was submitted