Point any HTML form at one endpoint. 500 free submissions — no card, no time limit — and unlimited forms.
Create free accountThe 30-second checklist
- Open DevTools → Network, submit once, and inspect the actual request's method, Content-Type and Payload. Check each hop if it redirects.
- If a field is missing from the payload, give it a
nameand make sure it is enabled and associated with the submitted form. - If the payload contains fields, match its encoding to the parser in the table below. In Express, register middleware before the handler.
- For
fetchwith FormData, remove any manually assigned Content-Type and send the object directly, withoutJSON.stringify. - For files, use multipart; for GET, read the query string. Look for a 301/302 that changed your POST into a GET.
An empty JavaScript object on the server does not prove that the browser sent nothing. Compare what left the browser with what the server parsed. Use dummy values while debugging so contact details and uploaded files do not end up in logs.
Cause 1: inputs have an id but no name
HTML form submission and new FormData(form) collect named controls. An id connects a label or JavaScript selector to an element; it does not supply a submitted key. A visible, filled input without a name is omitted silently.
<!-- Missing from the submitted payload -->
<input id="email" type="email" value="jane@example.com">
<!-- Sent as email=jane%40example.com in a URL-encoded form -->
<input id="email" name="email" type="email" value="jane@example.com">Inspect the captured entries inside your submit handler, after the user has entered their values:
const data = new FormData(form);
console.log([...data.entries()]); // inspect keys and values, not just the objectA console preview of FormData {} can be misleading. The entries are the useful check. See the HTML name attribute reference and the FormData JavaScript guide. Also confirm that a control outside the form has a matching form attribute.
Cause 2: fields are disabled before capture
Disabled controls are excluded, including controls disabled through a parent fieldset, subject to the first-legend exception. Disabling the entire form before constructing FormData can therefore remove the values you intended to send. Capture the data first, then disable the send button while the request runs.
const data = new FormData(form); // capture while fields are enabled
submitButton.disabled = true;
try {
const response = await fetch(form.action, { method: "POST", body: data });
if (!response.ok) throw new Error("Submission failed");
} finally {
submitButton.disabled = false;
}For supported text controls, readonly prevents editing while retaining submission. It does not apply to selects or checkboxes. Unchecked checkboxes and radio buttons are also omitted by design, and only the activated submit button contributes its name/value in native submission. Validate every received value on the server, including hidden or read-only values.
Cause 3: Content-Type and the server parser disagree
The header describes the bytes in the request body. Changing only the header does not convert multipart into JSON or JSON into a URL-encoded form. A normal POST form defaults to URL encoding, fetch with FormData sends multipart, and JSON.stringify produces JSON text.
| Sent Content-Type | Express | PHP | Flask |
|---|---|---|---|
application/x-www-form-urlencoded | express.urlencoded() → req.body | $_POST | request.form |
multipart/form-data with boundary | Multer → req.body for text; req.file or req.files for files | $_POST for text; $_FILES for files | request.form for text; request.files for files |
application/json | express.json() → req.body | json_decode(file_get_contents('php://input'), true) | request.get_json() |
Express: register parsers before routes
req.body undefined or an empty object commonly means the parser never ran, or did not match the media type. These built-in parsers handle ordinary forms and JSON, respectively:
import express from "express";
const app = express();
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.post("/contact", (req, res) => {
// Validate req.body before using it.
res.json({ received: req.body });
});Middleware declared after this route cannot populate the body before the handler reads it. Neither built-in parser handles multipart, even if your FormData contains only text. Add Multer to the relevant route:
import multer from "multer";
const upload = multer({
dest: "uploads/",
limits: { fileSize: 5 * 1024 * 1024, files: 1, fields: 20 },
});
app.post("/upload", upload.single("attachment"), (req, res) => {
// Text fields: req.body; uploaded file: req.file
res.json({ received: req.body, hasFile: Boolean(req.file) });
});
// A separate multipart endpoint that accepts text fields only:
app.post("/contact-multipart", upload.none(), (req, res) => {
res.json({ received: req.body });
});Install Multer in your Express project and match attachment to the file input's name. upload.none() rejects files. Keep upload middleware scoped to upload routes, validate files, handle size errors, and clean up temporary uploads after processing. These examples echo fields for local diagnosis; remove that echo for production.
PHP: JSON does not populate $_POST
<?php
// For a URL-encoded or multipart POST:
$email = $_POST['email'] ?? null;
// Multipart uploads are in $_FILES, not $_POST.
// For a separate endpoint expecting application/json:
$payload = json_decode(
file_get_contents('php://input'),
true,
512,
JSON_THROW_ON_ERROR
);
// Validate that $payload has the expected structure before using it.Choose the reader that matches the request; these are alternatives, not two required parsing steps. Handle malformed JSON as a client error. If small forms work but a large multipart POST leaves both $_POST and $_FILES empty, check PHP's post_max_size. Check upload_max_filesize and individual file error codes too.
Flask: select form fields, files or JSON
from flask import Flask, request
app = Flask(__name__)
@app.post("/contact")
def contact():
if request.is_json:
data = request.get_json()
# Validate the expected JSON structure.
return {"received": data}
email = request.form.get("email")
attachment = request.files.get("attachment")
return {"email": email, "has_file": attachment is not None}An empty request.form is expected for JSON or a file-only multipart body. Calling request.get_json() on a non-JSON request can produce a 415 response in current Flask; fix the request encoding instead of forcing JSON parsing on form data.
Cause 4: a manual multipart header drops the boundary
// Broken: no boundary in this manually assigned header.
fetch("/upload", {
method: "POST",
headers: { "Content-Type": "multipart/form-data" },
body: new FormData(form),
});
// Correct: the browser sets Content-Type AND the matching boundary.
fetch("/upload", { method: "POST", body: new FormData(form) });The boundary tells a multipart parser where each field starts and ends. A missing or mismatched boundary can cause a parse error or empty fields. Remove a default application/json header from your fetch wrapper too. The actual Network request should show a header like multipart/form-data; boundary=....
Cause 5: JSON.stringify(FormData) sends an empty object
FormData entries are not enumerable object properties, so JSON.stringify(new FormData(form)) produces {}. The request reaches the server successfully, but the fields were never serialized.
// For multipart: send the FormData object directly.
await fetch("/contact-multipart", { method: "POST", body: new FormData(form) });
// For a text-only JSON API: preserve repeated names as arrays.
const data = new FormData(form);
const payload = Object.create(null);
for (const name of new Set(data.keys())) {
const values = data.getAll(name);
if (values.some(value => value instanceof File)) {
throw new Error("Use multipart for file uploads");
}
payload[name] = values.length === 1 ? values[0] : values;
}
await fetch("/contact", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});Object.fromEntries(data) is shorter for single-value text fields, but keeps only the last value for repeated names. File objects need multipart, not this JSON conversion. See how to send form data to an API for choosing an encoding.
Cause 6: a native file form is missing enctype
Without multipart encoding, a native POST form sends the file name rather than the file bytes. Your text fields may arrive while the upload collection stays empty. Set enctype="multipart/form-data" on the form:
<form action="/upload" method="post" enctype="multipart/form-data">
<input name="email" type="email" required>
<input name="attachment" type="file" required>
<button type="submit">Upload</button>
</form>This attribute controls native submission. When JavaScript sends a FormData body with fetch, the browser generates multipart encoding regardless of the form's enctype. The server still needs a multipart parser.
Cause 7: GET forms send query parameters, not a body
A form without a method defaults to GET. Its fields appear in a URL such as /search?term=forms, so an empty body is correct. Read req.query in Express, $_GET in PHP, or request.args in Flask. Use POST when your endpoint expects a request body, and avoid placing sensitive values in URLs. See GET vs POST forms.
Cause 8: a 301/302 redirect changes POST to GET
Browsers and fetch normally follow a 301 or 302 after POST with a GET, discarding the body. A trailing-slash redirect, HTTP-to-HTTPS upgrade or hostname redirect can make the final handler look broken even though the first request contained every field.
Enable Preserve log in the Network panel and inspect the first request and its Location response header. Point your form action or fetch URL directly at the final HTTPS endpoint. If you control a redirect that must preserve the method and body, use 307 or 308. A 303 deliberately changes the follow-up to GET and is appropriate for a success-page redirect after the POST has been processed.
Use the form action tester to inspect an action URL. To compare a received request's headers and body with what you expected to send, use the webhook tester with sample data.
Frequently asked questions
Why is req.body undefined or empty in Express?
Register express.urlencoded() for URL-encoded forms and express.json() for JSON before your routes. Neither parses multipart/form-data: use route-scoped Multer middleware for FormData and uploads. Also check the actual request method, Content-Type, payload and redirect chain in the browser Network panel.
Why is $_POST empty in PHP even though I sent a POST?
PHP populates $_POST for application/x-www-form-urlencoded and multipart/form-data POST requests, not JSON. For application/json, decode file_get_contents('php://input'). Uploaded files are in $_FILES. If an entire large multipart submission is empty, check post_max_size as well as upload_max_filesize.
Why is Flask request.form empty when I send JSON?
request.form contains parsed URL-encoded or multipart text fields. For a JSON request, send Content-Type: application/json and call request.get_json(). Multipart files are in request.files, and GET query parameters are in request.args. A file-only multipart request can have an empty request.form while request.files contains the upload.
Why does JSON.stringify(new FormData(form)) return {}?
FormData stores entries through its own API, not as enumerable object properties, so JSON.stringify does not serialize its fields. Send FormData directly as the fetch body. For a text-only JSON API, build a plain object first, preserving repeated field names as arrays; do not use this conversion for file uploads.
Should I set Content-Type when sending FormData with fetch?
No. The browser generates multipart/form-data with a boundary matching the encoded body. Setting only Content-Type: multipart/form-data yourself omits that boundary and can cause empty fields or a parsing error. Remove the header, including any default JSON header inherited from an API wrapper.
Parser references: Express body parsing, Multer multipart middleware, PHP $_POST, and the Flask request API.
Skip server parsing with a hosted form endpoint
If you only need to collect contact submissions, splitforms accepts URL-encoded forms, multipart and JSON at https://splitforms.com/api/submit. Include your access key; splitforms handles parsing, stores accepted submissions and sends email notifications. You still need named, enabled fields and a correctly encoded request, but you do not need an Express, PHP or Flask handler.
<form action="https://splitforms.com/api/submit" method="POST">
<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY">
<input name="email" type="email" required>
<textarea name="message" required></textarea>
<button type="submit">Send</button>
</form>Use your own key from the splitforms dashboard. Validation and spam checks still apply; inspect the endpoint's response while testing. For a JavaScript submission, keep the hidden access key in the captured FormData and leave Content-Type to the browser.