1. Computing

Discuss in my forum

The Method Attribute of the Form Tag

HTML Forms Tutorial

By

The method attribute tells the server how to submit the form information. There are two methods, get and post. The default method is get.

method="get"

This sends the form information by including it on the URL. The get method sends the information to the server in one step. It is best used for forms where the information is not secure (as it can be seen in the URL), and the amount of information passed is small. Get requests are useful if you want to call a CGI from a link.

<form method="get" action="">

When to use the get method:

  • Short forms, with only 1 or 2 input fields
  • Forms with primarily select, radio, and checkbox fields
  • When the form needs to be called from a link
  • For mailto forms

method="post"

This sends the form information in the HTTP environment. It is a little more secure, as your customers can't see it directly (although it is sent in clear text, so it can be hijacked by hackers with packet sniffers). The post method sends the data to the server in two steps. First the browser contacts the server and after the contact is made, it sends the information. It is best used when you have a lot of information to pass (either textarea tags, or just a lot of fields.)

<form method="post" action="">

When to use the post method:

  • Longer forms, more than 3 input fields
  • Forms with large textarea fields
  • Forms where security is more important (but if security is important, you should use a secure server too)

This article is part of the HTML Forms Tutorial

  1. About.com
  2. Computing
  3. Web Design / HTML
  4. HTML and XHTML
  5. XHTML
  6. Forms
  7. HTML Form Tags
  8. Method Attribute - HTML Forms Tutorial - Using the Method Attribute

©2014 About.com. All rights reserved.