[Solved]- Photon AP Mode Form Post Request Not Working

I have been working with the Photon in AP/Listening mode and have it sending a page with a HTML page with a form that has the method set to POST. However, whenever I press the submit button from the form, nothing happens. I do have debug output so that I can monitor the data as the Photon receives HTML requests.

I am able to get standard page requests and get requests, but post requests in particular don’t seem to work (the loading of the page just pauses and never finishes).

Here is the page that gets sent:

const char* formpostpage =
R"(<!DOCTYPE html>
<title>Form Test Page</title>

<form enctype="text/plain" id="testFormId" method="post" name="testForm" action="/get.html">
<p style="text-align: center;">This is the form testing page for the POST request<br />
<input name="txtTestbox" type="text" value="This is a textbox" /><br />
<input name="btnTestbut" type="submit" value="POST Submit" /></p>


And here is the handler for the HTTP requests:

void myPage(const char* url, ResponseCallback* cb, void* cbArg, Reader* body, Writer* result, void* reserved)
// Ensure that our Serial is working
    serialBegun = true;

Serial.println("HTTP REQUEST");

// Make index equal to index.html
if (strcmp(url,"/index")==0)
    Header h("Location: /index.html\r\n");
    cb(cbArg, 0, 301, "text/plain", &h);
    // Iderate through the available pages
    int8_t idx = 0;
    for (;;idx++)
        Page& p = pages[idx];
        if (!p.url) // If we reach the null page, send the 404
            idx = -1;
        else if (strncmp(url, p.url, strlen(p.url))==0) // If we match an url, break with the propper idx value
        //else if (((String)url).substring(0, strlen(p.url)+1) == (String)p.url)
            Serial.print("Page Requested: ");

    if (idx==-1) // When we didn't find the page, send the 404
        cb(cbArg, 0, 404, nullptr, nullptr);
    else // Send back the page we want to send
        Serial.print("Page Sent: ");
        // Get output of result
        Serial.print("Body size: ");
        // Try to grab data
        if (body->bytes_left) 
            char* data = body->fetch_as_string(); // Grab our data
            // handle the body data
            Serial.print("Data: ");
            // free the data! IMPORTANT!
            Serial.println("No data detected");
        // Send our page
        cb(cbArg, 0, 200, pages[idx].mime_type, nullptr);
        Serial.print("Url: "); Serial.println(url);

I was able to fix the issue by removing the enctype="text/plain" from the form.

1 Like

Thank you for posting your solution! This is a big help to people that might run into the same issue as you!