For the method attribute what are the differences between POST and GET?

In the form element, the method attribute can send data via either POST or GET. But I’m having trouble understanding which one to use and when? I tried to find an answer at w3schools, but just wasn’t getting it. Can someone give me a simple answer with examples?
Cheers,
Mark

1 Like

always use POST for sensitive data (login form, register form and so forth). POST will not display the information in the address/url bar.

get will display the information in the URL bar which means the page can be bookmarked (unlike post), get is useful for searching, lets say you have a search box, then get is a good idea.

56 Likes

Thank you for your explanation.

So in the exercise example where they have used “GET” it is on a form which has username and password. would this not be classed as sensitive data? so why was “POST” not used?

The exercise linked to this topic is:

https://www.codecademy.com/courses/learn-html/lessons/html-form-validation/exercises/minlength-maxlength

if that doesn’t work, its:

https://www.codecademy.com/learn/learn-html > lesson form validation > 4. checking text length.

The only example in this lesson:

<form action="/example.html" method="POST">
  <label for="summary">Summarize your feelings in less than 250 characters</label>
  <input id="summary" name="summary" type="text" minlength="5" maxlength="250" required>
  <input type="submit" value="Submit">
</form>

which a post.

So please clarify which exercise and example you are referencing.

But the topic you replied is related to a very different exercise then your question it seems. This topic is a split of this FAQ:

FAQ: Learn HTML: Form Validation - Checking Text Length

So please tell me which exercise this is.

you should use post, certainly with a login page and sensitive data like password and email.

I think you may be seeing something completely different as i have definitely replied to the post "for the method attribute what are the differences between "post and “Get”

That is what this topic is named, but its related to an FAQ about a specific exercise:

image

and you are getting an example from a very different exercise, so I am trying to establish where your example is coming from

Because using GET for a login form is bad practice. You should use POST, that should cover your question

But if there is mis-information somewhere, I need to know where so it can be fixed.

As you will see “GET” is used the whole way through the fore mentioned “Form Validation lesson”

This lesson is not representative of a real world example. The validation happens the front-end. Although front-end validation an be useful to reduce the amount of server request and provide instant feedback, you always need back-end validation.

Which is not done in this lesson, I assume to not overwhelm new learners.