Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added brief description of get and post method of form line 26-51 #28971

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions intermediate_html_css/forms/form_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,35 @@ Later in the curriculum, we will learn to hook backend systems up to frontend fo
The second is the `method` attribute which tells the browser [which HTTP request method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) it should use to submit the form.
The GET and POST request methods are the two you will find yourself using the most.

We use GET when we want to retrieve something from a server. For example, Google uses a GET request when you search as it *gets* the search results.
We use GET when we want to retrieve something from a server. In the **GET** method, form data is appended to the URL as query parameters. For example, if you search for "HTML forms" on a site using GET, the URL might look like this:
```
https://example.com/search?q=HTML+forms
```
Here, the form's input (`q=HTML+forms`) is visible in the URL. This is useful for bookmarking or sharing, but not secure for sensitive data like passwords or personal details. Additionally, the URL has a character limit, restricting how much data can be sent.

POST is used when we want to change something on the server, for example, when a user makes an account or makes a payment on a website.
POST is used when we want to change something on the server, for example, when a user makes an account or makes a payment on a website.In the **POST** method, form data is sent in the request body rather than the URL, so it is not visible in the address bar. For example, when submitting a login form:

```html
<form action="https://example.com/login" method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Log In">
</form>
```
The submitted data is sent in the request body like this:
```
POST /login HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 40

username=JohnDoe&password=securePassword123
```
This makes POST more suitable for handling sensitive or large data, such as passwords or file uploads.
The markup for creating a form element looks like this:

```html
```
<form action="example.com/path" method="post">

</form>
```

Expand Down
Loading