HTTP Methods Explained

Understand what really happens when a form is submitted — HTTP requests, GET query strings, POST request bodies, and form encoding types.

Step 1 of 5

What happens when you click Submit — step by step

You've been using forms that submit data, but what actually happens under the hood? Understanding this process removes the mystery and helps you build better forms.

When a user clicks a submit button, the browser performs these steps in order:

Step 1: Collect the data. The browser finds every form element inside the <form> that has a name attribute. For each one, it creates a name-value pair: the name is the key, and whatever the user entered (or selected) is the value. Elements without a name attribute are silently ignored.

Step 2: Encode the data. The name-value pairs are converted into a specific text format. Special characters are encoded (spaces become + or %20, & becomes %26, etc.). This encoding ensures the data can be safely transmitted over the internet.

Step 3: Build the HTTP request. The browser creates an HTTP request using the form's method (GET or POST) and action (the destination URL). For GET, the encoded data is appended to the URL. For POST, it's placed in the request body.

Step 4: Send the request. The browser sends the HTTP request to the server at the specified URL. This is exactly the same process as when you type a URL in the address bar and press Enter — the browser makes an HTTP request and waits for a response.

Step 5: Display the response. The server processes the data, then sends back an HTTP response (usually a new HTML page). The browser displays this response, replacing the current page. This is why the page "refreshes" when you submit a traditional form.

Think of it this way: Think of form submission like packing a suitcase for a trip. First, you gather all the items you need (collecting form data). Then you fold and organize them neatly so they fit properly (encoding the data). Next, you choose how to travel — carry-on bag where everyone can see what you're carrying (GET), or a locked checked bag (POST). You hand the bag to the airline (sending the HTTP request), they transport it to your destination (the server), and your host unpacks it and responds to your arrival (the server's response).