mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge remote-tracking branch 'upstream/develop' into 4.4
This commit is contained in:
commit
e80b66f1bb
@ -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"' : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user