Moin, ich hänge hier gerade fest: client.print("<input type='radio' name=r value=1> One<br>"); client.print("<input type='radio' name=r value=2> Two<br>"); client.print("<input type='radio' name=r value=3> Three<br>"); client.print("<input type=submit value=submit></form>"); client.print("</body></html>"); value = // was muss ich hier machen, um den Wert 1,2 oder 3 zuzuweisen? Die Buttons werden auf der erstellten Webseite angezeigt, der "submit"-Button auch, und dann weiss ich nicht weiter. Vermutlich nur ne Kleinigkeit, aber welche? danke Thomas
So oder so ähnlich mache ich es html_header.h
1 | const char MY_HTTP_HEADER[] PROGMEM = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/><title>{v}</title>"; |
2 | const char MY_HTTP_STYLE[] PROGMEM = "<style>.c{text-align: center;} div,input{padding:5px;font-size:1em;} input[type=text]{width:95%;} input[type=radio] {width=30%;} body{text-align: center;font-family:verdana;} button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;} .q{float: right;width: 64px;text-align: right;}</style>"; |
3 | const char MY_HTTP_HEADER_END[] PROGMEM = "</head><body><div style='text-align:left;display:inline-block;min-width:260px;'>"; |
4 | const char MY_HTTP_BODY_END[] PROGMEM = "</div></body></html>"; |
main.cpp
1 | #include "WiFi.h" |
2 | #include "ESPAsyncWebServer.h" |
3 | |
4 | AsyncWebServer server(80); |
5 | |
6 | void setup() { |
7 | //...
|
8 | WiFi.begin(SSID, WIFIPASS); |
9 | while (WiFi.status() != WL_CONNECTED) { |
10 | delay(500); |
11 | Serial.print("."); |
12 | }
|
13 | server.on("/blubb", HTTP_GET, handleBLUBB); |
14 | server.on("/blubb", HTTP_POST, handlepostBLUBB); |
15 | |
16 | }
|
17 | void handleBLUBB(AsyncWebServerRequest *request){ |
18 | String page = FPSTR(MY_HTTP_HEADER); |
19 | page.replace("{v}", "Radio Buttons"); |
20 | |
21 | page += FPSTR(HTTP_HEADER_END); |
22 | page += F("<h1>Radiobuttons</h1><br />"); |
23 | page += F("<form action=\"/blubb\" method=\"post\">"); |
24 | page += F("<input type='radio' name=r value=1> One<br>"); |
25 | page += F("<input type='radio' name=r value=2> Two<br>"); |
26 | page += F("<input type='radio' name=r value=3> Two<br>"); |
27 | page += F("<input type=submit value=submit></form>"); |
28 | |
29 | page += FPSTR(MY_HTTP_BODY_END); |
30 | |
31 | request->send(200, "text/html",page); |
32 | }
|
33 | |
34 | void handlepostBLUBB(AsyncWebServerRequest *request){ |
35 | String page = FPSTR(MY_HTTP_HEADER); |
36 | |
37 | page.replace("{v}", "Geiler Titel"); |
38 | page += FPSTR(HTTP_STYLE); |
39 | page += FPSTR(HTTP_HEADER_END); |
40 | |
41 | int params = request->params(); |
42 | for(int i=0;i<params;i++){ |
43 | AsyncWebParameter* p = request->getParam(i); |
44 | if(p->isPost()){ |
45 | page += "POST[" + String(p->name().c_str()) + "]: " + String(p->value().c_str()) + "<br />"; |
46 | }
|
47 | }
|
48 | page += FPSTR(MY_HTTP_BODY_END); |
49 | |
50 | request->send(200, "text/html",page); |
51 | }
|
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.