From 6b6703dab1eef265325e4c03f5bda3e8a39d6b63 Mon Sep 17 00:00:00 2001 From: Andrei Furnica Date: Thu, 2 Aug 2018 15:55:03 +0300 Subject: [PATCH] fix form helper set_radio --- system/Helpers/form_helper.php | 2 +- tests/system/Helpers/FormHelperTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index 384b2d09665d..fcac0adbabe8 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -925,7 +925,7 @@ function set_radio(string $field, string $value = '', bool $default = false): st // Unchecked checkbox and radio inputs are not even submitted by browsers ... $result = ''; - if (!empty($request->getPost()) || !empty(old($field))) + if (!empty($input = $request->getPost($field)) || !empty($input = old($field))) { $result = ($input === $value) ? ' checked="checked"' : ''; } diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php index daf865189497..867f969be897 100644 --- a/tests/system/Helpers/FormHelperTest.php +++ b/tests/system/Helpers/FormHelperTest.php @@ -756,6 +756,10 @@ public function testSetCheckbox() } // ------------------------------------------------------------------------ + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function testSetRadio() { $_SESSION = [ @@ -771,6 +775,10 @@ public function testSetRadio() unset($_SESSION['_ci_old_input']); } + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function testSetRadioFromPost() { $_POST['bar'] = 'baz';