Skip to content

Commit d12785a

Browse files
committed
fix: set_checkbox() incorrect checking
set_checkbox() with default true checks unchecked checkbox when redirected back with input.
1 parent a970e22 commit d12785a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

system/Helpers/form_helper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,11 @@ function set_checkbox(string $field, string $value = '', bool $default = false):
629629
return '';
630630
}
631631

632+
$session = Services::session();
633+
$hasOldInput = $session->has('_ci_old_input');
634+
632635
// Unchecked checkbox and radio inputs are not even submitted by browsers ...
633-
if ((string) $input === '0' || ! empty($request->getPost()) || ! empty(old($field))) {
636+
if ((string) $input === '0' || ! empty($request->getPost()) || $hasOldInput) {
634637
return ($input === $value) ? ' checked="checked"' : '';
635638
}
636639

0 commit comments

Comments
 (0)