catcode.com > Guide to HTML Forms > The <form> HTML element > get and post

get and post

The get method

When you specify method="get" in your <form> tag, the information that enter into your form will be tacked on to the end of the action= address.

For example, go to Yahoo! and type computers in the search area. After you click the Search button, look at the Location area near the top of your browser window. It shows:

http://search.yahoo.com/bin/search?p=computers

The first part in red is the action address. The part in green includes the word you typed. The neat part of the get method is that you don't have to even use a form to send the data. As a further experiment, in your browser, erase the word computers from the location area, and type printers instead. When it looks like what you see below, press Enter.

http://search.yahoo.com/bin/search?p=printers

The get method is agnostic -- it doesn't know (or care) where its input came from. In the first case, it came from Yahoo's search form. In the second case, it came from something you typed in the location area. You can even take the contents of the location area and cut and paste it into a hypertext link:

<a href="http://search.yahoo.com/bin/search?p=printers">Search Yahoo for Printers</a>

And it looks like this: Search Yahoo for Printers

With all these advantages, why use any other method? Well, first, many servers will put an upper limit to how many characters you can tack on after the destination address. This upper limit is usually somewhere around 2000 bytes. Second, there are times when you just don't want to put the information in the location bar, which tells the whole universe, “Hey, look at what this guy typed!!!!”

The post method

The post method sends your data to the server “behind the scenes” by putting it on what computer folks call standard input. The information on your form won't appear in the location area, so the screen looks a bit cleaner. Furthermore, servers will put a larger upper limit on the number of bytes that can be transmitted via the post method; usually around 32000.

Of course, the disadvantage of post is that you can't cut and paste the information into a link.

Which Should I Use?

Some scripts are designed to accept information only from the get method; others are designed to react only to post data. If this is the case, the webmaster and programmer you're working with will tell you which method to use. In the absence of any explicit instructions, we recommend post because it doesn't mess up the location area, and it will normally accept more data.