by Dinesh Thakur Category: HTML

In general, when a visitor clicks the "submit" button, two things are sent to the server: the data that the visitor typed into the form, and an action, which basically tells .the server the name of the program, which knows how to process the form's data.

The user's data may contain arbitrary characters with special meaning like spaces, ampersands, equal signs etc., Some of these characters have a special meaning for the web browser. For example, the ampersand is used by the browser to separate the name = value pairs in the query string passed to the server. So if the user's data contains ampersands, the browser may be in trouble.

So the browser for a safe alternative translates any characters that are likely to cause trouble. Space character (" ") is converted to plus (+) sign. and other special characters such as ampersands (&) or percent (%) are replaced by a Sequence %hh where hh is hexadecimal representation of the numeric code for the character replaced. So the user data:

Name = Dinesh Thakur

Address = Nirankari Road New Delhi.
email = This email address is being protected from spambots. You need JavaScript enabled to view it.

will be encoded by the browser as

Name=Dinesh+Thakur&Address= Nirankari+Road+New+Delhi &Email= 
 This email address is being protected from spambots. You need JavaScript enabled to view it.

Next we will discuss how to send the encoded data to the server.

 Method Attribute: Get and Post Methods

The method attribute tells the browser how to send the encoded data to the server. It can have either get or post as its value. when no method is specified. Get is used as default. These method & have different characteristic and so need different treatment.

A get form submission is performed by fetching URL made up of the location of the CGI form handler program followed by a question mark ‘(“?”) and then followed by the encoded form data. For example, the values used earlier in this .I -"- section might be submitted as Nirankari+Road+New+Delhi & Email = 
 This email address is being protected from spambots. You need JavaScript enabled to view it.
  (just for example)

You can see this data by looking at the "address barf! of the browser's window. This method invokes a perl CGI program in the server's cgi-bin directory to process the user’s data. Now this cgi program creates a new HTML document in response to the user's information and sends this page back to the server! Which in turn passes it to the browser from which the request was sent.

Because the form data is included as part—of the URL in a get request! the reply to the form submission is likely to be remembered by caching: browsers and caching HTTP proxy servers. For this reason; it is advisable to. use get as the method attribute of forms that a ways yield the same result for the same input. For example, in a search form which is using a get method, the same document could be searched more than once.

So if more than one client requests for searching of the same kind of information, the proxy servers instead of the main server are able to decide for the reply. This had been made possible because the proxy servers are able to view the encoded data sent by the and they would send the same pages, cached at their location during the first request, to this request rather than making the main server process it again.

Your choice will also be determined by the amount of form data. In general get is used for small amount and post is used for large amount of form data. In get, you are limited to a total of 255 characters, including the URL encoding overhead. So, if you are sending information from a complicated form, you may lose data by overflowing the maximum buffer size for the URL.

On the other hand, with the post method the browser doesn’t append variables to the URL like get does. Instead, the post method connects to the web server! And then browser sends each value from the HTML form to the web server.

The POST method can handle any amount of data, because the browser sends the data as a separate stream. The POST method should be used to send potentially large amounts of data to a web server. This method has no character-length limitations, and is the only option for sending information from a complex form.

This is one of the reasons that the Internet community has moved toward the post method. Because this method is easily distinguished from an ordinary URL fetch and the form data is in an attached document rather than part of the URL (as in get), this sort of request is 'rarely remembered by caching proxy servers and so post should be used as the method attribute of the forms that can produce different results for the same input.

Action Attribute

After collecting the form data, we use the action attribute to tell the browser where to send the data. Mainly, there are two ways:

1. You can have the form data emailed directly to you using the mailto action.

2. You can send the data to a CGI script for processing.

In the first approach, you need to use a mailto URL for the action attribute, i.e. like

<FORM method= post action mailto: ecomputernotes@gmail>.com >

Now the form data can be emailed to a specific address. So you can get the form data directly into your mailbox and then can save it to some database for further processing. The data that you receive in your mailbox may not be in a readable format. Instead of some thing nice and neat like:

Name=Dinesh Thakur

Address=Nirankari Road New Delhi.
Email= This email address is being protected from spambots. You need JavaScript enabled to view it.

you will get something like this:

Name=Dinesh+Thakur&Address= Nirankari+Road+New+Delhi&Email = 
 This email address is being protected from spambots. You need JavaScript enabled to view it.

There are several utilities available on the net to convert this raw data to a human readable format. Form Post Edit is one such utility available through

Sometimes depending on the sender's browser / email configuration, using the mailto action just brings up an empty New Mail Window instead of sending the form data. That is why this mailto action is simpler but not entirely reliable. So we now move on to the second approach ie. using a CGI form handler. This is the most reliable approach to process your form data. Here the data is sent to a CGI script on a server for processing. The action attribute contains the URL of CGI script. The most obvious place to look for such a script is your own ISP or web host. Most of them have a mail script that you can send the data to. If you look at their help pages for such CGI scripts, you will probably find directions for using their script i.e. how to set your action attribute.

If for some reason your ISP or web host is unable to provide a form mail script, you may use one of many free form processing services on the net. These are simply form mail scripts that reside somewhere else but are offered for use to the general public. Another option is to run your own script but for that you must have access to your server's CGI bin.

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.