From 1f7e7ddb9f476a652627da6ab9976c5c9735e69c Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Tue, 30 Apr 2019 02:22:32 +0900 Subject: [PATCH] Fixed the value of AutoConnectElements not reflected. Issue #64 --- README.md | 1 + src/AutoConnect.cpp | 28 ++++++++++++++-------------- src/AutoConnectAux.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 298c89f..190844e 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ Full documentation is available on https://Hieromon.github.io/AutoConnect, some - Supports new element type **AutoConnectFile** and built-in file uploader. - Supports a **format attribute** with the AutoConnectText element. - Fixed blank page responds with Configure new. +- Fixed the value of AutoConnectElements not reflected. - Changed menu labels placement in source files structure. ### [0.9.7] Feb. 25, 2019 diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index 1c4bfc0..4ab45b8 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -794,20 +794,20 @@ bool AutoConnect::_classifyHandle(HTTPMethod method, String uri) { // If the current request argument contains AutoConnectElement, it is // the form data of the AutoConnectAux page and with this timing save // the value of each element. - if (_webServer->hasArg(String(F(AUTOCONNECT_AUXURI_PARAM)))) { - _auxUri = _webServer->arg(AUTOCONNECT_AUXURI_PARAM); - _auxUri.replace("/", "/"); - AutoConnectAux* aux = _aux.get(); - while (aux) { - if (aux->_uriStr == _auxUri) { - // Save the value owned by each element contained in the POST body - // of a current HTTP request to AutoConnectElements. - aux->_storeElements(_webServer.get()); - break; - } - aux = aux->_next.get(); - } - } + // if (_webServer->hasArg(String(F(AUTOCONNECT_AUXURI_PARAM)))) { + // _auxUri = _webServer->arg(AUTOCONNECT_AUXURI_PARAM); + // _auxUri.replace("/", "/"); + // AutoConnectAux* aux = _aux.get(); + // while (aux) { + // if (aux->_uriStr == _auxUri) { + // // Save the value owned by each element contained in the POST body + // // of a current HTTP request to AutoConnectElements. + // aux->_storeElements(_webServer.get()); + // break; + // } + // aux = aux->_next.get(); + // } + // } // Here, classify requested uri if (uri == _uri) { diff --git a/src/AutoConnectAux.cpp b/src/AutoConnectAux.cpp index 5b16f83..bbdb500 100644 --- a/src/AutoConnectAux.cpp +++ b/src/AutoConnectAux.cpp @@ -370,6 +370,28 @@ const String AutoConnectAux::_indicateEncType(PageArgument& args) { const String AutoConnectAux::_insertElement(PageArgument& args) { String body = String(""); + // When WebServerClass::handleClient calls RequestHandler, the parsed + // http argument has been prepared. + // If the current request argument contains AutoConnectElement, it is + // the form data of the AutoConnectAux page and with this timing save + // the value of each element. + WebServerClass* _webServer = _ac->_webServer.get(); + if (_webServer->hasArg(String(F(AUTOCONNECT_AUXURI_PARAM)))) { + _ac->_auxUri = _webServer->arg(String(F(AUTOCONNECT_AUXURI_PARAM))); + _ac->_auxUri.replace("/", "/"); + AutoConnectAux* aux = _ac->_aux.get(); + while (aux) { + if (aux->_uriStr == _ac->_auxUri) { + // Save the value owned by each element contained in the POST body + // of a current HTTP request to AutoConnectElements. + aux->_storeElements(_webServer); + break; + } + aux = aux->_next.get(); + } + } + + // Call user handler before HTML generation. if (_handler) { if (_order & AC_EXIT_AHEAD) { AC_DBG("CB in AHEAD %s\n", uri()); @@ -377,9 +399,11 @@ const String AutoConnectAux::_insertElement(PageArgument& args) { } } + // Generate HTML for all AutoConnectElements contained in the page. for (AutoConnectElement& addon : _addonElm) body += addon.toHTML(); + // Call user handler after HTML generation. if (_handler) { if (_order & AC_EXIT_LATER) { AC_DBG("CB in LATER %s\n", uri());