ESP32 HTML send string back to server help

I have a project using ESP32 and Arduino to set up a simple web server which works okay, using libraries:
#include <WebServer.h>
#include <WiFi.h>
But I'm a bit stuck with a seemingly simple problem; how do I get user input back to a string in the ESP32?
I have tried examples found online but can't get it to work. Something seems to be missing.
My code serves a web page with the following elements to try to get SSID from the user:
SSID
Save
which creates an input text box for the user to type into and a save button to send the string.
This displays correctly on a browser.

In the ESP32 Arduino code I have the following:

void handle_OnConnect(){                                                // this is called when home web page is requested
  LEDStatus = LOW;


  if(server.method() == HTTP_ANY) {      // try
    String ssid = server.arg("ssid");
    Serial.print("got value: ");
    Serial.println(ssid);
  }

  Serial.println("web request");
  server.send(200, "text/html", getMainPageHTML());
}

But this code never gets triggered. I don't believe my HTML code is causing the browser to send anything back to the server!
Does anybody have any tips or examples I that will help me figure this out?

I'd recommend using ESPAsyncWebServer on your ESP32

If you are trying only to provide a UI to collect connexion information, may be you'll like WiFiManager and its captive portal approach.

Thanks for the suggestions. If I was starting from scratch I would try them but my project is already well developed and I just need to add some method of getting user input back to the ESP32.

OK - I don't use WebServer.h

Have you looked at the examples?

I've looked at some, but there are so many examples I don't know where to start.
Can't find anything that addresses my issue.

I created a similar webserver using Nodemcu i can share the code if you want

that would be great. Thank you

Login code

Please take a look at: http://jurca.dyn.ts.si/

I'm using a different web server but client Javascript code should work just the same.

The server gets text from the client through the URL. If it is a complicated text it should be base64 encoded and the server should base63 decode it after receiving.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.