HTML Forms: Collect and Submit User Information
A form groups controls
A form collects information using controls such as inputs. A named text input contributes a name and its current value. A submit button starts submission; the action identifies the destination. This is a local demonstration, not a working search service.
<form action="/search" method="get"> <label> Topic <input name="topic" value="HTML"> </label> <button type="submit">Search</button></form>The browser displays an editable field and a submit button. Its initial data contains topic=HTML.
GET and POST
GET places encoded form data in the destination URL query; it is appropriate for retrieval such as search. POST normally sends data in the request body. Server code must handle the chosen method; no server is provided here. URLs can be stored in history and logs, so never use GET for passwords.
<form action="/feedback" method="post"> <label> Feedback <input name="message" value="Useful"> </label> <button type="submit">Send</button></form>The form declares POST and the fictional endpoint /feedback.
Which values are included?
The name is the key, not the visible label. Disabled controls are omitted. A control with no name is also omitted. An enabled named text input with an empty value can still contribute an empty string.
<form> <label> City <input name="city" value="Baku"> </label> <label> Note <input value="Draft"> </label> <label> Code <input name="code" value="7" disabled> </label> <label> Extra <input name="extra"> </label></form>The initial data has city=Baku and an empty extra value, not Note or Code.
Common mistakes and practice
Do not nest forms. A control without a name is not included in ordinary form data; id alone is not enough. Use GET for retrieval and POST for operations that change server state. POST alone is not encryption. These examples use illustrative endpoints that are not implemented; type fictional data only and do not submit from the preview. Try changing a field name and predict the resulting pair.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Forms: Collect and Submit User Information — Knowledge Check
Apply the form-control concepts from this lesson.
Which attribute supplies the key in submitted form data?
Which method is appropriate for a catalog search that does not change server state?
A named text control is disabled. What happens to its value?
A text field has id but no name. What happens in ordinary form data construction?
What does the form action identify?