Refresh webform automatically after submit so values are right.

This commit is contained in:
mattbk 2023-09-05 11:08:01 -05:00
parent c65bc22028
commit 2060df9691

View File

@ -61,10 +61,18 @@ const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head> <!DOCTYPE HTML><html><head>
<title>ESP Input Form</title> <title>ESP Input Form</title>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<script> <script type='text/javascript'>
// Submit timestamps as unix seconds
var putDate = function(form) { var putDate = function(form) {
form.inputTimeUnix.value = Math.floor(Date.now() / 1000); form.inputTimeUnix.value = Math.floor(Date.now() / 1000);
document.getElementById("js_start_time_unix").value = (Date.parse(js_start_time_unix_entry.value))/1000;
}; };
// Refresh page after submit so values are right https://stackoverflow.com/a/1860732/2152245
window.onload = function() {
document.getElementById("hidden-form").onload = function() {
top.location.reload();
}
}
</script></head><body> </script></head><body>
<form action="/get" target="hidden-form" onsubmit="putDate(this);"> <form action="/get" target="hidden-form" onsubmit="putDate(this);">
@ -99,10 +107,7 @@ const char index_html[] PROGMEM = R"rawliteral(
<input type="submit" value="Submit""> <input type="submit" value="Submit"">
</form> </form>
<iframe style="display:none" name="hidden-form"></iframe> <iframe style="display:none" name="hidden-form" id="hidden-form"></iframe>
<script>
document.getElementById("js_start_time_unix").value = (Date.parse(js_start_time_unix_entry.value))/1000;
</script>
</body></html>)rawliteral"; </body></html>)rawliteral";
// Auxiliary variables to store the current output state // Auxiliary variables to store the current output state