mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #1836] Checkbox always return true #1544
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#1544
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mylms on GitHub (Sep 18, 2025).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1836
I am using a web interface with a checkbox. If I open the website (config portal), configure and save the settings, everything is fine.
However, if I do not save the settings or do not open the config portal at all (timeout), the values from the checkboxes are always set to true.
Textbox or numeric box always work fine
Does anyone have any advice?
`
//PORTAL CONFIG
char time24hoursCheckbox[30] = "type='checkbox'";
if(mode24hour) strcat(time24hoursCheckbox, " checked");
WiFiManagerParameter config_cfg_mode1224("config_cfg_mode1224", "Mode 24 hours
", "T", 2, time24hoursCheckbox, WFM_LABEL_AFTER);
wm.addParameter(&config_cfg_mode1224);
//PoRTAL START
wm.setConfigPortalTimeout(60);
wm.setConfigPortalBlocking(true);
wm.startConfigPortal("ClockCfgPortal");
//GET DATA FROM PORTAL
mode24hour = (strncmp(config_cfg_mode1224.getValue(), "T", 1) == 0);
`
@dmadison commented on GitHub (Oct 27, 2025):
You set the value to "T" and consider it checked by comparing if the value is "T". If you do not save or open the portal it is going to use the default value, which you set to "T". The "checked" attribute, set as a string, is unused in reading back the state of the checkbox unless the form is submitted and the manager class modifies the parameter's value.
The underlying problem is that the parameter "current value" is the same as the parameter "default value", since the code was originally written with text input in mind. For checkboxes the value is a constant and should not be overridden; the checkbox only determines whether the value is submitted in the form.
I had the same problem as you. As-is I don't think the library supports checkboxes well. I submitted my solution as PR #1775:
The checkbox class manages the 'checked' state as a separate bool, which is then used to set the 'checked' attribute. The class handles the string comparison on form submission automatically in the callback function.
@mylms commented on GitHub (Oct 28, 2025):
I made my own solution. I programmed the web portal completely myself...with the help of Chat GPT :) I added some functions that are not there or are complicated to use.
It's not as elegant as WiFi manager, but I write the page as classic HTML code and get the data back directly into variables. Moreover, basically all HTML/CSS tags work.
@tablatronix commented on GitHub (Nov 29, 2025):
Is there a checkbox example, I forget?
Please use it when filing bugs or enhancements, thanks