tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.63k stars 1.98k forks source link

Reading the settings made in custom html inputs #1758

Open edpgcooper opened 3 months ago

edpgcooper commented 3 months ago

I am trying to make a couple of drop-down lists for configuring my device. I followed the example here OnDemandConfigPortal.ino

I can present a drop-down of the four options as provided in the example, but I cannot work out how to read the selected option back.

My callback is

void saveParamCallback(){
  Serial.println("[CALLBACK] saveParamCallback fired");

  Serial.print("getValue: ");
  Serial.println(custom_html_inputs.getValue());   // Seem to get no return.

  Serial.print("getID: ");
  Serial.println(custom_html_inputs.getID());      // Seem to get no return.

  Serial.print("getLabel ");
  Serial.println(custom_html_inputs.getLabel());    // Seem to get no return.

  Serial.print("getCustomHTML ");
  Serial.println(custom_html_inputs.getCustomHTML()); // I just get the html I provided back, can't see the selection.

  // wm.stopConfigPortal();
}

This results in this output, note I have selected Option 1

[CALLBACK] saveParamCallback fired
getValue: 
getID: 
getLabel 
getCustomHTML 
  <!-- INPUT SELECT -->
  <br/>
  <label for='input_select'>Label for Input Select</label>
  <select name="input_select" id="input_select" class="button">
  <option value="option1">Option 1</option>
  <option value="option2" selected>Option 2</option>
  <option value="option3">Option 3</option>
  <option value="option4">Option 4</option>
  </select>
edpgcooper commented 3 months ago

Figured it out, probably obvious to anyone who's worked with HTML stuff on ESP before.

void saveParamCallback(){
  String selectedOption = "None";

  Serial.println("[CALLBACK] saveParamCallback fired");

  selectedOption = wm.server->arg("input_select");
  Serial.println("Selected option: " + selectedOption);
}
tablatronix commented 3 months ago

I think the param child class lets you automatically set args to param values. I totally forget how this works..