AD JB Toolbox 01 EN

HTML Tutorial / Form Structure and GET vs. POST

A form groups controls whose values users submit. To understand where the data goes, distinguish the controls' name attributes, the destination in action, and the request method in method. HTML can build the input interface, but saving or searching data requires a server-side handler.

Build a small search form

The example accepts a search term. Replace /search with a real endpoint before using it on a site.

<form action="/search" method="get">
  <label for="keyword">Search term</label>
  <input id="keyword" name="q" type="search">
  <button type="submit">Search</button>
</form>

The label's for matches the input's id, giving the field a name. name="q" identifies the value in the submitted data. Entering “HTML” typically produces a URL containing ?q=HTML. An id without a name can still connect a label, but the field's value is normally not included in the submission.

action names the destination; method chooses how the browser sends the values. If both are omitted, the form submits to the current URL using GET by default. Try a term with spaces or non-ASCII letters: the address bar may show an encoded representation of those characters. That is a transport format, not a sign that the input disappeared.

Choose GET or POST

GET places the form data in the URL query string. It suits searches and filters that users may bookmark or share. Do not use it to send passwords or other sensitive values because the data is visible in the URL. POST sends form data in the request body and is commonly used for operations that change server state, such as creating an account or submitting a message. POST does not encrypt data by itself; sensitive submissions need HTTPS and appropriate server handling.

<form action="/contact" method="post">
  <label for="message">Message</label>
  <textarea id="message" name="message"></textarea>
  <button type="submit">Send</button>
</form>

/contact is an illustrative path. Without a server at that address, the request may lead to an error page. A path beginning with / is relative to the site's root, so it is not a working handler when you simply open a local file. To inspect GET without a server, set the first example's action="" and observe the URL after submission. A local file URL may display differently across browsers. Do not submit personal information to an example endpoint.

Why might a field be missing from submitted data?

A disabled control cannot be edited and is not submitted. If you need an uneditable value to be submitted, check whether that control type supports readonly. Only checked checkboxes and radio buttons contribute their values. A file upload requires additional form settings and server processing; adding a file input to this example alone is not enough.

If the result is unexpected, first check each control's name, then whether a selectable control is checked, then whether the URL and method match the server. A browser's Network panel can show the request even when the server responds with an error. A correct request does not imply that the server saved the value. See the MDN form reference for submission details.

More in This Category
HTML Tutorial / Form Structure and GET vs. POST

HTML Tutorial / Form Structure and GET vs. POST

Understand how form action, method, and control names determine where form values go, and when GET or POST is appropriate.

HTML Tutorial / Links: Paths, Page Fragments, and Email

HTML Tutorial / Links: Paths, Page Fragments, and Email

Create HTML links with absolute or relative URLs, jump to a document fragment, and add email, new-tab, or download links. Learn what to verify before publishing.

HTML Tutorial / Choose Input Types for Email, Numbers, Dates, and Choices

HTML Tutorial / Choose Input Types for Email, Numbers, Dates, and Choices

Choose input types based on the value being collected and understand how checkboxes and radio groups behave when submitted.

HTML Tutorial / Table Basics: table, tr, th, and td

HTML Tutorial / Table Basics: table, tr, th, and td

Build a basic HTML data table with rows and header or data cells, then organize its headings and body without using tables for page layout.

HTML Tutorial / Syntax

HTML Tutorial / Syntax

Learn the essential rules of HTML syntax, including elements, tags, attributes, void elements, comments, nesting, and the structure of a complete HTML document.

HTML Tutorial / Accessible Tables: caption, scope, and Spanning Cells

HTML Tutorial / Accessible Tables: caption, scope, and Spanning Cells

Make table headings and data relationships clear with caption, th, and scope, and learn when colspan or rowspan makes a table harder to read.

HTML Tutorial / Explain Forms with fieldset, legend, and autocomplete

HTML Tutorial / Explain Forms with fieldset, legend, and autocomplete

Group related controls with fieldset and legend, and use suitable autocomplete tokens to describe the purpose of input fields.

HTML Tutorial / Images: img, Alt Text, and Dimensions

HTML Tutorial / Images: img, Alt Text, and Dimensions

Add an image with HTML img, write useful alternative text, and set width and height correctly. A downloadable example helps you test file paths and sizing.

HTML Tutorial / Text Semantics: Emphasis, Quotations, Abbreviations, and Code

HTML Tutorial / Text Semantics: Emphasis, Quotations, Abbreviations, and Code

Learn when to use HTML em, strong, q, blockquote, abbr, code, and kbd. Examples show how each element conveys meaning rather than just changing the appearance of text.

HTML Tutorial / Connect Labels and Inputs Correctly

HTML Tutorial / Connect Labels and Inputs Correctly

Connect labels to inputs with for and id, distinguish id from submitted name, and learn why placeholder text cannot replace a label.