GET is suited to requests such as searching or filtering, where the values can safely appear in a shareable URL. POST is usually more suitable for changes or submissions that should not appear in the URL. We will keep the example small, so you can see how the fields work without building a whole application first.
What You Need to Know
POST does not encrypt data by itself: use HTTPS for private information. Never put passwords or secrets in a GET query string.
GET is convenient for search terms, but never submit passwords or other sensitive information through a query string.
Example: See It in Action
This example keeps the idea small. Copy it carefully, then follow the explanation instead of guessing what the browser will do.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<form action="/search" method="get">
<label for="q">Search</label>
<input id="q" name="q" type="search">
<button type="submit">Search</button>
</form>
Let’s Understand the Example
- Input creates a form control. Its type decides whether people type text, choose a date, move a slider and more.
- Label tells people what a control is for. For connects the label to the control with the matching id.
- Action names the destination where the browser sends a form submission. A real server handler must exist there.
- Method controls how a form submits; GET makes values part of the URL, while POST sends them in the request body.
- For links a label to the input whose id matches, so clicking the label can focus the control.
- Id gives one element a unique name within the page, so a link, label, or script can point to it.
The browser can submit values with keys such as q. A control without a name normally contributes no entry. Whether the submission produces a result depends on the action URL and the server behind it.
What Should You See?
You should see controls for Search. The example uses an input of type search and sends a GET request when submitted. If the action points to a missing server endpoint, the browser cannot complete the task.
Choose one field and predict its submitted name and value. Then change the value and check whether the browser accepts it. Do not assume that a working-looking form has a real server behind it.
Try It Yourself
- Predict what the search URL looks like after entering a two-word query.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Submitting a password field with GET because it seems simpler.
- Client-side HTML validation is a helpful first check, not a security boundary. A real receiving application must validate the values again.
Key Takeaways
- GET is suited to requests such as searching or filtering, where the values can safely appear in a shareable URL.
- Input creates a form control. Its type decides whether people type text, choose a date, move a slider and more.
- GET is convenient for search terms, but never submit passwords or other sensitive information through a query string.