HTML form input to a string
Posted: Mon Aug 03, 2015 3:02 am
How do you make a webpage on the server with a text input field, the data from which would be stored in a string variable.
The code I managed to write/copy/paste to this point:
It creates an html form that doesn't do much, but I couldn't find what the snprintf() function is supposed to do and what aruments it needs. Most importantly - I couldn't find any info on how to implement the form to have the input data stored in a string after the user clicks the submit button. I saw people doing similar stuff with client.println(), client.read(), but I still couldn't figure it out. Thanks!
The code I managed to write/copy/paste to this point:
Code: Select all
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char *ssid = "ESPap";
const char *password = "thereisnospoon";
ESP8266WebServer server(80);
void handleRoot() {
int sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;
char temp[420];
snprintf ( temp, 400,
"<html>\
<head>\
<title>ESP8266 Demo</title>\
<style>\
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
<h1>Hello from ESP8266!</h1>\
<p>Uptime: %02d:%02d:%02d</p>\
<form action='http://192.168.4.1' method='get'>\
F_name: <input type='text' name='fname'><br>\
<input type='submit' value='Submit'>\
</form>\
</body>\
</html>",
hr, min % 60, sec % 60
);
server.send(200, "text/html", temp);
}
void setup() {
delay(1000);
WiFi.softAP(ssid, password);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
server.on("/", handleRoot);
server.begin();
}
void loop() {
server.handleClient();
}
It creates an html form that doesn't do much, but I couldn't find what the snprintf() function is supposed to do and what aruments it needs. Most importantly - I couldn't find any info on how to implement the form to have the input data stored in a string after the user clicks the submit button. I saw people doing similar stuff with client.println(), client.read(), but I still couldn't figure it out. Thanks!