[GH-ISSUE #1836] Checkbox always return true #1544

Open
opened 2026-02-28 01:30:28 +03:00 by kerem · 3 comments
Owner

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);
`

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<br>", "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); `
Author
Owner

@dmadison commented on GitHub (Oct 27, 2025):

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.

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:

// Portal Config
WiFiManagerParameterCheckbox config_cfg_mode1224("config_cfg_mode1224", "Mode 24 hours", "T", mode24hour, nullptr, WFM_LABEL_AFTER);
wm.addParameter(&config_cfg_mode1224);

// Portal Start
wm.setConfigPortalTimeout(60);
wm.setConfigPortalBlocking(true);
wm.startConfigPortal("ClockCfgPortal");

// Get Data From Portal
mode24hour = config_cfg_mode1224.getChecked();

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.

<!-- gh-comment-id:3453509994 --> @dmadison commented on GitHub (Oct 27, 2025): >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. 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: ```cpp // Portal Config WiFiManagerParameterCheckbox config_cfg_mode1224("config_cfg_mode1224", "Mode 24 hours", "T", mode24hour, nullptr, WFM_LABEL_AFTER); wm.addParameter(&config_cfg_mode1224); // Portal Start wm.setConfigPortalTimeout(60); wm.setConfigPortalBlocking(true); wm.startConfigPortal("ClockCfgPortal"); // Get Data From Portal mode24hour = config_cfg_mode1224.getChecked(); ``` 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.
Author
Owner

@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.

<!-- gh-comment-id:3458822876 --> @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.
Author
Owner

@tablatronix commented on GitHub (Nov 29, 2025):

Is there a checkbox example, I forget?

Please use it when filing bugs or enhancements, thanks

<!-- gh-comment-id:3591788008 --> @tablatronix commented on GitHub (Nov 29, 2025): Is there a checkbox example, I forget? Please use it when filing bugs or enhancements, thanks
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1544
No description provided.