Forms predate JavaScript and still work without it. A great deal of modern form code exists to reproduce behaviour the browser already provides, which is worth knowing before you write any of it.
The element and its two key attributes
<form action="/subscribe/" method="post"> <label for="email">Email address</label> <input type="email" id="email" name="email" required> <button type="submit">Subscribe</button> </form> The action attribute holds the address the data is sent to. The method attribute decides how it is sent. Everything else about a form follows from these two.
Omitting the action submits to the current page address, which is a common and legitimate pattern where the same script renders the form and processes it. Omitting the method defaults to a GET request, which is rarely what you want for anything that changes data.
What happens on submission
When a form is submitted the browser gathers every control that has a name attribute and a current value, assembles them into a set of name and value pairs, and sends them to the address in the action attribute using the specified method. The page then navigates to whatever the server returns.
That navigation is the part people forget. A traditional form submission is a page load, which is why a form that submits and appears to do nothing is often a form that reloaded so quickly the change was not noticed.
The name attribute is what gets sent
This is the single most common cause of missing data. The server receives names, not ids. An input with an id and no name is invisible to the server, and nothing warns you, because the form submits perfectly happily without it.
The id attribute exists for the label association and for CSS and scripting. The name attribute exists for submission. Most inputs need both, and they are frequently given the same value, which is fine and slightly obscures the fact that they do entirely different jobs.
Which controls are submitted
Not everything inside a form is sent. A control is included only if it has a name, is not disabled, and has a value the browser considers present.
Unchecked checkboxes and unselected radio buttons send nothing at all, rather than sending an empty value. This means server code checking for a checkbox has to test whether the key exists rather than what it contains. A disabled control is excluded entirely, which is a useful way to omit a field without removing it, and a readonly control is still submitted, which is the practical difference between the two.
Encoding types
The enctype attribute controls how the data is packaged. The default encodes it as a URL query string, which is fine for text.
File uploads require multipart encoding, and this is the second classic mistake: a file input inside a form with the default encoding submits the filename rather than the file. Nothing warns you, and the server receives a short string where a document should be.
<form action="/upload/" method="post" enctype="multipart/form-data"> Forms cannot be nested
One form inside another is invalid, and the parser will discard the inner one. Where a page needs several independent forms, they must be siblings.
If a control genuinely must sit outside its form in the markup, the form attribute lets it declare which form it belongs to by id, which resolves most layout situations that would otherwise tempt someone into nesting.
Intercepting submission with JavaScript
A script can listen for the submit event and prevent the default navigation, which is how a form is sent in the background without a page reload.
The important discipline is to build the form so it works without that script first, then enhance it. A form whose action attribute is empty or absent and which relies entirely on JavaScript is broken for anyone whose script fails to load, and it also loses the browser's own validation, autofill and restore behaviour.
Autocomplete belongs on the form too
Browsers offer to fill in known values, which saves users a great deal of typing and reduces errors. The autocomplete attribute on individual fields tells the browser what each one is for, using a defined set of values such as email, given-name or postal-code.
Turning autocomplete off across a whole form is a habit worth questioning. It is occasionally justified for a field where a stored value would be wrong, and it is frequently applied out of a vague sense of tidiness, at a real cost to anyone filling in a long form on a phone.
Do not skip the submit button
A form with no submit button can still be submitted by pressing enter in a text field, which many users rely on, but the behaviour becomes inconsistent once there are multiple fields. An explicit submit button is what makes the form obviously complete, and it is what a screen reader user expects to find at the end.