summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authornisheeth-barthwal <nisheeth.barthwal@nbaztec.co.in>2013-02-21 08:39:29 +0100
committernisheeth-barthwal <nisheeth.barthwal@nbaztec.co.in>2013-02-21 08:39:29 +0100
commit5e227994581f2325b4d10e90da6dadb113a4cde1 (patch)
tree0e97fd0a12a731d3cb17a15dd36fc6299419051b /system
parent32c1e626d51517418acbecadde9a83d67517e0a8 (diff)
Fix for issue #2236
Diffstat (limited to 'system')
-rw-r--r--system/helpers/form_helper.php33
-rw-r--r--system/libraries/Form_validation.php15
2 files changed, 43 insertions, 5 deletions
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index d6e3e85fa..200da8ac5 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -642,14 +642,37 @@ if ( ! function_exists('set_value'))
*/
function set_value($field = '', $default = '', $is_textarea = FALSE)
{
- if (FALSE === ($OBJ =& _get_validation_object()))
+ if (FALSE !== ($OBJ =& _get_validation_object()) && $OBJ->has_rule($field))
{
- return isset($_POST[$field])
- ? form_prep($_POST[$field], $is_textarea)
- : form_prep($default, $is_textarea);
+ return form_prep($OBJ->set_value($field, $default), $is_textarea);
+ }
+
+ // We couldn't find the $field in validator, so try in $_POST array
+ $index = $field;
+ $container = $_POST;
+
+ // Test if the $field is an array name, and try to obtain the final index
+ if (preg_match_all('/\[(.*?)\]/', $field, $matches))
+ {
+ sscanf($field, '%[^[][', $index);
+ for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
+ {
+ if (isset($container[$index]) && $matches[1][$i] !== '')
+ {
+ $container = $container[$index];
+ $index = $matches[1][$i];
+ }
+ else
+ {
+ $container = array();
+ break;
+ }
+ }
}
- return form_prep($OBJ->set_value($field, $default), $is_textarea);
+ return isset($container[$index])
+ ? form_prep($container[$index], $is_textarea)
+ : form_prep($default, $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