Form basics
Multipart form data
multipart/form-data is a way to encode a form submission as separate parts, one per field. HTML forms need it whenever they include a file upload.
Also called: enctype multipart, file upload form, FormData
When a form is submitted with POST, the browser has to turn the fields into one request body. It does that in one of two main ways, chosen by the enctype attribute.
The two encodings
application/x-www-form-urlencodedis the default. Fields becomename=Jane&email=jane%40example.com. It is compact and fine for text, but it cannot carry the contents of a file.multipart/form-datasplits the body into parts separated by a boundary string. Each part has its own headers, so one part can hold text and another a file with its filename and type.
HTML for a file upload
<form method="POST" action="https://api.staticform.app/api/v1/forms/YOUR_FORM_ID" enctype="multipart/form-data">
<input type="text" name="name" />
<input type="file" name="resume" />
<button type="submit">Send</button>
</form>
Without enctype="multipart/form-data", the browser sends only the filename and the file itself is lost.
Submitting with JavaScript
With fetch, pass a FormData object as the body. The browser then builds the multipart body and sets the Content-Type header, including the boundary. Do not set that header yourself: if you do, the boundary is missing and the server cannot read the parts.
Limits and validation
Uploads need limits on size and type, enforced on the server because the browser’s accept attribute is only a hint. See form validation.
In StaticForm
StaticForm accepts both encodings. A file field can allow several files, restrict file extensions and set a maximum size per file, up to a global limit of 25 MB per file. Uploaded files are stored with the submission, can be downloaded from the dashboard and can be attached to notification emails, each attachment with its own send condition. The JavaScript helper builds the FormData for you.
Learn more
Related terms
- GET vs POSTGET and POST are the two HTTP methods an HTML form can use. GET adds the fields to the URL, while POST sends them in the body of the request.
- Form actionThe form action is the HTML attribute that holds the URL a form is sent to when the visitor submits it. Without it, the form posts to the page it is on.
- Form validationForm validation is checking that the data a visitor submits is complete and in the right format, before it is accepted, stored or acted on.