summaryrefslogtreecommitdiffstats
path: root/system/helpers/form_helper.php
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/helpers/form_helper.php
parent32c1e626d51517418acbecadde9a83d67517e0a8 (diff)
Fix for issue #2236
Diffstat (limited to 'system/helpers/form_helper.php')
-rw-r--r--system/helpers/form_helper.php33
1 files changed, 28 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);
}
}