[GH-ISSUE #78] Any Way to add Custom Fields to be saved #54

Closed
opened 2026-02-28 01:23:07 +03:00 by kerem · 11 comments
Owner

Originally created by @yomasa on GitHub (Jan 19, 2016).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/78

I want to save the "mqtt_server" , "mqtt_port", "mqtt_user","mqtt_password" ?

Thanks
Jorge

Originally created by @yomasa on GitHub (Jan 19, 2016). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/78 I want to save the "mqtt_server" , "mqtt_port", "mqtt_user","mqtt_password" ? Thanks Jorge
kerem closed this issue 2026-02-28 01:23:07 +03:00
Author
Owner

@Jorgen-VikingGod commented on GitHub (Jan 20, 2016):

there is already support for custom fields:
https://github.com/tzapu/WiFiManager/blob/master/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino#L73-L93

<!-- gh-comment-id:173095277 --> @Jorgen-VikingGod commented on GitHub (Jan 20, 2016): there is already support for custom fields: https://github.com/tzapu/WiFiManager/blob/master/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino#L73-L93
Author
Owner

@tzapu commented on GitHub (Jan 20, 2016):

thanks Jorgen , mentioned in docs here https://github.com/tzapu/WiFiManager#custom-parameters

<!-- gh-comment-id:173098550 --> @tzapu commented on GitHub (Jan 20, 2016): thanks Jorgen , mentioned in docs here https://github.com/tzapu/WiFiManager#custom-parameters
Author
Owner

@Jorgen-VikingGod commented on GitHub (Jan 20, 2016):

@tzapu Wow, did not see the updated doc yet.
Awesome work - really like what you did

<!-- gh-comment-id:173104775 --> @Jorgen-VikingGod commented on GitHub (Jan 20, 2016): @tzapu Wow, did not see the updated doc yet. Awesome work - really like what you did
Author
Owner

@tzapu commented on GitHub (Jan 20, 2016):

thanks, could not have done it without all your guy's help

<!-- gh-comment-id:173106330 --> @tzapu commented on GitHub (Jan 20, 2016): thanks, could not have done it without all your guy's help
Author
Owner

@drvpn commented on GitHub (Jun 21, 2022):

I would love to see an example where a custom field input type was password. I have figured out how to add the field to the webpage but I cannot figure out how to store the password in a variable. custom_field.getValue() doesn't work.

Below is snippet of code how I added the field.

const char* custom_mpass_str = "<br/><label for='pwd'>MQTT Password:</label><input type='password' id='pwd' name='pwd'>";
new (&custom_field) WiFiManagerParameter(custom_mpass_str); // custom html input

wm.addParameter(&custom_field);

Does anyone know how I can get the pwd's value and store it in variable?

Thanks!

<!-- gh-comment-id:1161256364 --> @drvpn commented on GitHub (Jun 21, 2022): I would love to see an example where a custom field input type was password. I have figured out how to add the field to the webpage but I cannot figure out how to store the password in a variable. custom_field.getValue() doesn't work. Below is snippet of code how I added the field. ``` const char* custom_mpass_str = "<br/><label for='pwd'>MQTT Password:</label><input type='password' id='pwd' name='pwd'>"; new (&custom_field) WiFiManagerParameter(custom_mpass_str); // custom html input wm.addParameter(&custom_field); ``` Does anyone know how I can get the pwd's value and store it in variable? Thanks!
Author
Owner

@tablatronix commented on GitHub (Jun 21, 2022):

See the fs examples, spiffs etc

<!-- gh-comment-id:1161258554 --> @tablatronix commented on GitHub (Jun 21, 2022): See the fs examples, spiffs etc
Author
Owner

@drvpn commented on GitHub (Jun 21, 2022):

Thanks @tablatronix but unfortunately that example doesn't help. Below is all the parameters that is configured in https://github.com/tzapu/WiFiManager/blob/master/examples/Parameters/SPIFFS/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino and this method only works to create input type="text" not input type="password". I am looking to input an actual password, so people cannot shoulder surf and see the password.

WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6);
WiFiManagerParameter custom_api_token("apikey", "API token", api_token, 32);

Since I cannot use the above method to create a field with input type="password" I have found that I can add a password field like this:

const char* custom_mpass_str = "<br/><label for='pwd'>MQTT Password:</label><input type='password' id='pwd' name='pwd'>";
new (&custom_field) WiFiManagerParameter(custom_mpass_str); // custom html input
wm.addParameter(&custom_field);

This works but I cannot figure out how to get the value out of the webpage and into a variable. This follow method won't work:

strcpy(mqtt_server, custom_field.getValue());

So looks like I am stuck here unless I can find a way to retrieve the input value, when the form is submitted, and store it in a variable. Any ideas?

<!-- gh-comment-id:1161693695 --> @drvpn commented on GitHub (Jun 21, 2022): Thanks @tablatronix but unfortunately that example doesn't help. Below is all the parameters that is configured in https://github.com/tzapu/WiFiManager/blob/master/examples/Parameters/SPIFFS/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino and this method only works to create input type="text" not input type="password". I am looking to input an actual password, so people cannot shoulder surf and see the password. ``` WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40); WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6); WiFiManagerParameter custom_api_token("apikey", "API token", api_token, 32); ``` Since I cannot use the above method to create a field with input type="password" I have found that I can add a password field like this: ``` const char* custom_mpass_str = "<br/><label for='pwd'>MQTT Password:</label><input type='password' id='pwd' name='pwd'>"; new (&custom_field) WiFiManagerParameter(custom_mpass_str); // custom html input wm.addParameter(&custom_field); ``` This works but I cannot figure out how to get the value out of the webpage and into a variable. This follow method won't work: `strcpy(mqtt_server, custom_field.getValue());` So looks like I am stuck here unless I can find a way to retrieve the input value, when the form is submitted, and store it in a variable. Any ideas?
Author
Owner

@tablatronix commented on GitHub (Jun 21, 2022):

you can just add type='password' to the custom html parameter? not sure if there is another way to add password to an input.

<!-- gh-comment-id:1161720183 --> @tablatronix commented on GitHub (Jun 21, 2022): you can just add `type='password'` to the custom html parameter? not sure if there is another way to add password to an input.
Author
Owner

@drvpn commented on GitHub (Jun 21, 2022):

Thanks again @tablatronix I found a solution in an example that used radio buttons. It used the follow code and it seems to work with my custom password field as well. Here is the function that was required:

String getParam(String name) {
  //read parameter from server, for customhmtl input
   String value;
  if (wm.server->hasArg(name)) {
    value = wm.server->arg(name);
  }
  return value;
}

Here is the link to the solution I found: https://github.com/tzapu/WiFiManager/issues/1158#issuecomment-1047708779

Thanks so much for all your time!

<!-- gh-comment-id:1161730509 --> @drvpn commented on GitHub (Jun 21, 2022): Thanks again @tablatronix I found a solution in an example that used radio buttons. It used the follow code and it seems to work with my custom password field as well. Here is the function that was required: ``` String getParam(String name) { //read parameter from server, for customhmtl input String value; if (wm.server->hasArg(name)) { value = wm.server->arg(name); } return value; } ``` Here is the link to the solution I found: https://github.com/tzapu/WiFiManager/issues/1158#issuecomment-1047708779 Thanks so much for all your time!
Author
Owner

@tablatronix commented on GitHub (Jun 21, 2022):

  WiFiManagerParameter custom_input_type("input_pwd", "input pass", "", 15,"type='password'"); // custom input attrs (ip mask)

adding to the SUPER example

<!-- gh-comment-id:1161737356 --> @tablatronix commented on GitHub (Jun 21, 2022): ```C++ WiFiManagerParameter custom_input_type("input_pwd", "input pass", "", 15,"type='password'"); // custom input attrs (ip mask) ``` adding to the SUPER example
Author
Owner

@drvpn commented on GitHub (Jun 21, 2022):

@tablatronix That works like a charm and is far more intuitive than the getParam solution. Today you are my code hero, thanks so much! 🥇

<!-- gh-comment-id:1161753543 --> @drvpn commented on GitHub (Jun 21, 2022): @tablatronix That works like a charm and is far more intuitive than the getParam solution. Today you are my code hero, thanks so much! 🥇
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#54
No description provided.