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. Compare for, id, and the submission key name in Connect Labels and Inputs Correctly.

<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>

The /contact path is illustrative; without a handler it can return an error. To practice GET submission to the current document, remove action from the earlier form. A leading slash is relative to the site root, not a working endpoint in a local file. Do not submit real personal information to an example endpoint.

Inspect the data before sending it

Save the complete example as inspect-form.html. Omitting action targets the current document. An explicitly written action must be a valid, nonempty URL, so omit the attribute instead of writing action="" to mean the current page.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Form-data practice</title>
</head>
<body>
  <h1>Inspect submitted fields</h1>
  <form id="inspect-form" method="get">
    <p><label for="query">Search term</label>
      <input id="query" name="q" value="HTML" required></p>
    <p><label for="limit">Result limit</label>
      <input id="limit" name="limit" value="5" readonly></p>
    <p><label for="coupon">Unavailable coupon</label>
      <input id="coupon" name="coupon" value="DEMO" disabled></p>
    <p><label><input type="checkbox" name="news" value="yes" checked> News</label></p>
    <button type="submit">Inspect values in the URL</button>
  </form>
</body>
</html>

After opening the file, run this line in the developer tools Console to inspect the current field names and values. FormData is a web API for building a form-data list. This command itself neither sends the data over the network nor runs constraint validation.

Array.from(new FormData(document.getElementById("inspect-form")).entries())
[["q", "HTML"], ["limit", "5"], ["news", "yes"]]

Initially the readonly limit is included and the disabled coupon is omitted. Uncheck News and its entry disappears too. Clearing the search term still allows you to inspect an empty q value, but the submit button triggers required validation. Compare data-list construction with interactive submission checks.

Method Inspect in Network Interpretation
GET Request URL/method and query parameters Names and values are encoded into the URL
POST Request URL/method and Form Data in the request body A failed response is separate from whether a request was sent

On a server-served page, open Network, submit, and inspect the corresponding request. A local file:// document is not equivalent to an HTTP GET or POST against a server. A 404 or 405 can reflect the destination or its supported method; removing field names or validation attributes does not solve that problem.

HTML submission-attribute rules · MDN FormData constructor

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. Test the constraints that block submission in Form Validation with required, Length, and Range Limits.

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.