Merge remote-tracking branch 'upstream/develop' into 4.4

This commit is contained in:
kenjis 2023-08-22 09:47:37 +09:00
commit e80b66f1bb
No known key found for this signature in database
GPG Key ID: BD254878922AF198
2 changed files with 27 additions and 1 deletions

View File

@ -629,8 +629,11 @@ if (! function_exists('set_checkbox')) {
return ''; return '';
} }
$session = Services::session();
$hasOldInput = $session->has('_ci_old_input');
// Unchecked checkbox and radio inputs are not even submitted by browsers ... // Unchecked checkbox and radio inputs are not even submitted by browsers ...
if ((string) $input === '0' || ! empty($request->getPost()) || ! empty(old($field))) { if ((string) $input === '0' || ! empty($request->getPost()) || $hasOldInput) {
return ($input === $value) ? ' checked="checked"' : ''; return ($input === $value) ? ' checked="checked"' : '';
} }

View File

@ -866,6 +866,29 @@ final class FormHelperTest extends CIUnitTestCase
$this->assertSame(' checked="checked"', set_checkbox('foo', '0', true)); $this->assertSame(' checked="checked"', set_checkbox('foo', '0', true));
} }
/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/7814
*/
public function testSetCheckboxWithUnchecked(): void
{
$_SESSION = [
'_ci_old_input' => [
'post' => [
],
],
];
$this->assertSame(
'',
set_checkbox('fruit', 'apple', true)
);
$this->assertSame(
'',
set_checkbox('fruit', 'apple')
);
}
/** /**
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled