Skip to content

Commit

Permalink
fix: set_checkbox() incorrect checking
Browse files Browse the repository at this point in the history
set_checkbox() with default true checks unchecked checkbox
when redirected back with input.
  • Loading branch information
kenjis committed Aug 14, 2023
1 parent a970e22 commit d12785a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,11 @@ function set_checkbox(string $field, string $value = '', bool $default = false):
return '';
}

$session = Services::session();
$hasOldInput = $session->has('_ci_old_input');

// 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"' : '';
}

Expand Down

0 comments on commit d12785a

Please sign in to comment.