From 5e227994581f2325b4d10e90da6dadb113a4cde1 Mon Sep 17 00:00:00 2001 From: nisheeth-barthwal Date: Thu, 21 Feb 2013 13:09:29 +0530 Subject: Fix for issue #2236 --- system/helpers/form_helper.php | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'system/helpers/form_helper.php') 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); } } -- cgit v1.2.3-24-g4f1b From a7447d205296eeead94617f4b66707e336547b51 Mon Sep 17 00:00:00 2001 From: nisheeth-barthwal Date: Thu, 21 Mar 2013 15:48:10 +0530 Subject: Added array notation for keys in Input library --- system/helpers/form_helper.php | 44 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 692909c79..d2c22b05c 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -642,14 +642,17 @@ 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 form_prep($OBJ->set_value($field, $default), $is_textarea); + } + + if (FALSE !== ($OBJ =& _get_input_object()) && ($value = $OBJ->post($field, FALSE, TRUE))) { - return isset($_POST[$field]) - ? form_prep($_POST[$field], $is_textarea) - : form_prep($default, $is_textarea); + return form_prep($value, $is_textarea); } - return form_prep($OBJ->set_value($field, $default), $is_textarea); + return form_prep($default, $is_textarea); } } @@ -1004,5 +1007,36 @@ if ( ! function_exists('_get_validation_object')) } } +// ------------------------------------------------------------------------ + +if ( ! function_exists('_get_input_object')) +{ + /** + * Input Object + * + * Fetches the input object + * + * @return mixed + */ + function &_get_input_object() + { + $CI =& get_instance(); + + // We set this as a variable since we're returning by reference. + $return = FALSE; + + if ( ! isset($CI->input) OR ! is_object($CI->input)) + { + return $return; + } + else + { + $return = $CI->input; + } + + return $return; + } +} + /* End of file form_helper.php */ /* Location: ./system/helpers/form_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a5bcfb1d291d42521b0dc420b1b501c36710277d Mon Sep 17 00:00:00 2001 From: nisheeth-barthwal Date: Sat, 23 Mar 2013 10:53:51 +0530 Subject: Removed $recurse parameter in lieu of auto parsing. Changed "provision" entry. --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index d2c22b05c..2238af92a 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -647,7 +647,7 @@ if ( ! function_exists('set_value')) return form_prep($OBJ->set_value($field, $default), $is_textarea); } - if (FALSE !== ($OBJ =& _get_input_object()) && ($value = $OBJ->post($field, FALSE, TRUE))) + if (FALSE !== ($OBJ =& _get_input_object()) && ($value = $OBJ->post($field, FALSE))) { return form_prep($value, $is_textarea); } -- cgit v1.2.3-24-g4f1b From 77236e055234cbbc9f6ca6be472c70077a1f5856 Mon Sep 17 00:00:00 2001 From: nisheeth-barthwal Date: Mon, 25 Mar 2013 23:42:36 +0530 Subject: Simplified notation parsing and other cosmetic fixes --- system/helpers/form_helper.php | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 2238af92a..443a06a2d 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -647,7 +647,8 @@ if ( ! function_exists('set_value')) return form_prep($OBJ->set_value($field, $default), $is_textarea); } - if (FALSE !== ($OBJ =& _get_input_object()) && ($value = $OBJ->post($field, FALSE))) + $CI =& get_instance(); + if (NULL !== ($value = $CI->input->post($field, FALSE))) { return form_prep($value, $is_textarea); } @@ -1007,36 +1008,5 @@ if ( ! function_exists('_get_validation_object')) } } -// ------------------------------------------------------------------------ - -if ( ! function_exists('_get_input_object')) -{ - /** - * Input Object - * - * Fetches the input object - * - * @return mixed - */ - function &_get_input_object() - { - $CI =& get_instance(); - - // We set this as a variable since we're returning by reference. - $return = FALSE; - - if ( ! isset($CI->input) OR ! is_object($CI->input)) - { - return $return; - } - else - { - $return = $CI->input; - } - - return $return; - } -} - /* End of file form_helper.php */ /* Location: ./system/helpers/form_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 47ea5a8b99e17e9513be57d0af92f9e2637569b2 Mon Sep 17 00:00:00 2001 From: nisheeth-barthwal Date: Tue, 26 Mar 2013 18:57:28 +0530 Subject: Code fixes in line with suggestions --- system/helpers/form_helper.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 443a06a2d..e2c0cc4c5 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -642,18 +642,13 @@ if ( ! function_exists('set_value')) */ function set_value($field = '', $default = '', $is_textarea = FALSE) { - if (FALSE !== ($OBJ =& _get_validation_object()) && $OBJ->has_rule($field)) - { - return form_prep($OBJ->set_value($field, $default), $is_textarea); - } - $CI =& get_instance(); - if (NULL !== ($value = $CI->input->post($field, FALSE))) - { - return form_prep($value, $is_textarea); - } - return form_prep($default, $is_textarea); + $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($value === NULL ? $default : $value, $is_textarea); } } -- cgit v1.2.3-24-g4f1b