-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: For set_checkbox, when default is true the checkbox will become checked when redirected back with input. #7814
Comments
Yes, This behavior is from CI3, so maybe this is the spec? |
@WrestlingPotato If you could fix this issue, please send a PR. |
Ah, CI3 does not have The workaround is not to use the redirect. |
I found a bug in the documentation: #7816 |
I'm just starting to learn CI4, so I don't know how to fix the issue, and wanted to bring attention to the issue. For now I just gave up on having the checkbox be checked by default. |
use set_value('fruit', $fruit === 'apple' ? true : false) ? $fruit it _POST value |
@WrestlingPotato No problem. I found how to fix. Try #7818 |
PHP Version
8.1
CodeIgniter4 Version
4.3.5
CodeIgniter4 Installation Method
Manual (zip or tar.gz)
Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
No response
What happened?
<input type="checkbox" name="fruit" value="apple" <?= set_checkbox("fruit", "apple", true) ?>>
The input is part of a user submitted form.
When the view is generated, I want the checkbox to be checked by default. Then the user submits their form, the controller validates the information, then is redirected accordingly.
However, when the user is redirected back with input, 'fruit' is checked, even when the user unchecks it.
I suspect that this is because when 'fruit' is unchecked, 'fruit' is not added to $_POST, then when set_checkbox does not find an old value, which causes it to use the default value, which is checked. I think this because my CI_ENVIRONMENT is development, and I can see that _ci_old_input does not contain 'fruit'.
Steps to Reproduce
have
<input type="checkbox" name="fruit" value="apple" <?= set_checkbox("fruit", "apple", true) ?>>
in the view,
then
return redirect()->back()->withInput();
in the controller, after the user submits the form
Expected Output
Checkbox should be checked by default, then checked/unchecked according to user input when redirected back with input.
Anything else?
No response
The text was updated successfully, but these errors were encountered: