ESP32 - Webserver with 2 webpages and one form

Viewed 693

I need to program a ESP32 to act as webserver and have 2 simple pages.

The first one should contain a form that the user has to fill in. (one text box, one dropdown and one checkbox.) The form has a submit button, and when it is pressed, the values are written to the ESP32, and a new page is presented. This new page will the update its content dynamically via AJAX calls.

I've found and seen countless tutorials and managed to make the second AJAX page that updates on its own without refreshing. I am not able to undertand tough how I can make the / root page with the form to submit its data, AND to forward to the second page.

So basically the questions are 3:

  1. how can i have more than one page on a ESP32?
  2. how can I submit a form so that the values get stored in variables on the ESP?
  3. how can the submit button forward to the next page?

Thank you

-----EDIT:------

I found an answer to questions 1 and 3 with this sample: https://www.arduinoslovakia.eu/blog/2019/4/esp8266---http-server-s-viac-strankami?lang=en

question 2 is still open tough. Thank you!

1 Answers

You need to parse the incoming url, depending on the request you are sending with your form. The most common is a POST request, regarding to HTML forms.

If you send a POST request to your ESP, then your data will be in the body and you should parse in there. You will get a request like this (Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)

POST /test HTTP/1.1
Host: foo.example
Content-Type: application/x-www-form-urlencoded
Content-Length: 27

field1=value1&field2=value2

With a GET request you need to parse it from the incoming URL. The incoming url will like following:

foo.example/?field1=value1&field2=value2
Related