:: ENGLISH ::  PORTUGUêS ::


Beer, wine or water? What do you drink?
 

Beer

45.5%

Wine

18.2%

Water

9.1%

I don't drink

27.3%

Partners:

Server time

02:58
01-August-2010

Location: Home Page > Tutorials > 427642357

HTML TAGS - Forms

Let me start by telling you that all the pieces of information here are very important. If you seriously want to learn all about the HTML tags and attributes that we can use in a form then make a very careful reading. HTML forms must be well implemented to avoid crackers breaking your Web site. I've placed information along the tutorial to point out some possible dangers. Let's begin.

What's a HTML form?
It's the part of a Web page where the user will enter some input, by typing, checking or by clicking buttons and then sent it to the server for processing. It can be a login form or a forum form, the usage varies, but the objective is certain, you what some information from the user.
Every HTML form has the form tag. It states the beginning of the form and must always be present. It also informs the browser where to send the form, how and what type is the information that we want to sent. The form attributes are: action, method and enctype.
Note: The HTML tag form has been present in HTML since version 2.
The action attribute specifies the address where we will complete the form, this means that we must indicate here, the location of the page that will process the form. Let's say that the form page is called index.html and that the page processing the input is validade.html. If they are both in the same folder the action would be:
<form action="www.youraddress.com/validate.html" ...
You can remove the www.youraddress.com absolute path and use it's relative path, like this:
<form action="validate.html" ...
Let's say that validate.html is a folder down the root path (in windows or MS-DOS root path is c:\ and / in Linux and Unix). That folder is called for example cgi-bin, then:
<form action="/cgi-bin/validate.html" ...
That sents the form to a page, script or application located at the server. You can also E-mail the form information if you don't want to process it. For example:
<form action=mailto:foo@bar.com ...
If you don't know or don't need to process that information, then this is a pretty good way to get it. mailto is defined in RCF 2368, read it later to know more.
The method attribute specifies how we are going to submit the form. It specifies which HTTP method we will use to send the form's contents. There are two types POST and GET.
Note: The GET method has been around since HTML 2 version and the POST since HTML 3.2
If we don't specify the method attribute, then it default to GET. More about GET and POST in URL see HTTP specification at RFC 2616.
The GET method will be appended to the URI specified by the action attribute with a question mark as a separator, and then, new URI is sent to the processing agent. The result could be for exemple:
http://www. youraddress.com/validate.html?message=Hello
You can see the information after sending the form (and change it) in the URI and there also problems when "sending large quantities of binary data or text containing non-ASCII characters" (source: RFC 1867 ). In the RFC 2616. You can also discover that the GET method should not be used to submit sensitive data because this will cause this data to be encoded in the Request-URI.
In the POST method the form data set is included in the body of the form and sent to the processing agent (you can't see it).
So now your form tag is something like:
<form action="validate.html" method="POST" ...

The enctype method specifies the representation of our form data. This determines the mechanism used to encode the form's contents. Here I let the browser worry it self because the default for POST and GET is application/x-www-form-urlencoded and I don't specify it normally but, if you have a form here a user will upload some files, then the enctype attribute must be multipart/form-data and the method must be POST. So a normal usage would be:
<form action="validate.html" method="POST">
Or
<form action="validate.html" method="POST" enctype="application/x-www-form-urlencoded">
Has for a file upload form:
<form action="validate.html" method="POST" enctype="multipart/form-data">
On the next tutorial we will start to see the tags we can use to try and get information form the users.

by André Ferreira in 2004-06-06
Translated by André Ferreira

See the Comments: 0 | Comment Tutorial
 

On-line: 4 Guests - 0 Members

[About]  [Rules]  [Privacy]  [Contact

© 2004-2005 André Ferreira