Skip to content

Commit

Permalink
Fix 0 value issue for checkbox also
Browse files Browse the repository at this point in the history
  • Loading branch information
musmanikram committed Mar 20, 2020
1 parent fa86c6c commit 0095146
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ function set_checkbox(string $field, string $value = '', bool $default = false):
}

// Unchecked checkbox and radio inputs are not even submitted by browsers ...
if (! empty($request->getPost()) || ! empty(old($field)))
if (intval($input) === 0 || ! empty($request->getPost()) || ! empty(old($field)))
{
return ($input === $value) ? ' checked="checked"' : '';
}
Expand Down

1 comment on commit 0095146

@colethorsen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to make it impossible to set a default as the intval($input) === 0 returns true even if nothing is submitted.

using set_checkbox('status', 1, true) with no form data submitted, doesn't return the expected ' checked="checked"'

Please sign in to comment.