From 67f6a5e0321cc5d71dc2adc8dc72c71e96408dac Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 13 Sep 2013 16:21:31 +0300 Subject: Fix array notation fields for set_select() as well --- system/helpers/form_helper.php | 35 ++++++++--------------------------- user_guide_src/source/changelog.rst | 3 +-- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 424bb7e64..20379efa7 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -675,37 +675,18 @@ if ( ! function_exists('set_select')) */ function set_select($field = '', $value = '', $default = FALSE) { - $OBJ =& _get_validation_object(); + $CI =& get_instance(); - if ($OBJ === FALSE) + if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) { - if ( ! isset($_POST[$field])) - { - if (count($_POST) === 0 && $default === TRUE) - { - return ' selected="selected"'; - } - return ''; - } - - $field = $_POST[$field]; - - if (is_array($field)) - { - if ( ! in_array($value, $field)) - { - return ''; - } - } - elseif (($field == '' OR $value == '') OR $field !== $value) - { - return ''; - } - - return ' selected="selected"'; + return $CI->form_validation->set_select($field, $value, $default); + } + elseif (($input = $CI->input->post($field, FALSE)) === NULL) + { + return ($default === TRUE) ? ' selected="selected"' : ''; } - return $OBJ->set_select($field, $value, $default); + return ($input === $value) ? ' checked="selected"' : ''; } } diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index f6207750e..61293a3b3 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -596,7 +596,7 @@ Bug fixes for 3.0 - Fixed a bug (#2239) - :doc:`Email Library ` improperly handled the Subject when used with ``bcc_batch_mode`` resulting in E_WARNING messages and an empty Subject. - Fixed a bug (#2234) - :doc:`Query Builder ` didn't reset JOIN cache for write-type queries. - Fixed a bug (#2298) - :doc:`Database Results ` method ``next_row()`` kept returning the last row, allowing for infinite loops. -- Fixed a bug (#2236) - :doc:`Form Helper ` function ``set_value()`` didn't parse array notation for keys if the rule was not present in the :doc:`Form Validation Library `. +- Fixed a bug (#2236, #2639) - :doc:`Form Helper ` functions :func:`set_value()`, :func:`set_select()`, :func:`set_radio()`, :func:`set_checkbox()` didn't parse array notation for keys if the rule was not present in the :doc:`Form Validation Library `. - Fixed a bug (#2353) - :doc:`Query Builder ` erroneously prefixed literal strings with **dbprefix**. - Fixed a bug (#78) - :doc:`Cart Library ` didn't allow non-English letters in product names. - Fixed a bug (#77) - :doc:`Database Class ` didn't properly handle the transaction "test mode" flag. @@ -614,7 +614,6 @@ Bug fixes for 3.0 - Fixed a bug (#2590) - :php:func:`log_message()` didn't actually cache the ``CI_Log`` class instance. - Fixed a bug (#2609) - :php:func:`get_config()` optional argument was only effective on first function call. Also, it can now add items, in addition to updating existing items. - Fixed a bug in the 'postgre' :doc:`database ` driver where the connection ID wasn't passed to ``pg_escape_string()``. -- Fixed a bug (#2639) - :doc:`Form Helper ` functions :php:func:`set_radio()` and :php:func:`set_checkbox()` didn't parse array notation for keys if the rule was not present in the :doc:`Form Validation Library `. Version 2.1.4 ============= -- cgit v1.2.3-24-g4f1b