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.

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

Please clarify… I happened to use the GET option and it didn’t show on the bar… I tried running this code on a different browser and vs code as my code editor…
how does one really tell the difference between POST AND GET

can I see what you did? I can’t solve a problem from such a vague description.

If you have anchor element:

<a href="https://discuss.codecademy.com">discuss</a>

clicking on the link will execute a GET request and change the url in the address bar.

ok… thank you very much for this moderation…

But we were talking about GET and POST as values of the method attributes…

Why was GET used instead of POST since we were dealing on password which is classified sensitive… You said that POST is for sensitive data to hide it from the address bar…

This exercise isn’t representative of a real world scenario, the form is handles in the front-end using JavaScript, where normally you would make a request to the back-end

and then GET is very likely used to simplify the process of getting the data using JavaScript.

Well,

  • Method get is for getting information to fetch realtime data to the users and
  • Method post for securing and storing data to a specific path or server in an encrypted way.
  • In a word, post for storing and get for results. Both get and post is used to dealing with data.
  • For example, if you submit your information in an e-commerce site, then you will input or submit your data as a POST method and if you search in Google for something to see as your output, then you use GET method.

Thanks.

Thank you so much…
I think I understand this as a beginner level

1 Like

thank you so much too for your contributions

1 Like

You are most welcome to do so . thank you.