 is the method, which is either used as:
These two methods, POST and GET, refer to the standard HTTP metods of sending data across the internet. The GET method puts the data into the URL of the next page, so that it is visible in the browser's address bar, for example:
This has both an advantage and a disadvantage. The advantage is that URLs can easily be typed in or linked to using GET, although when using forms this is not vital. The disadvantage of this, though, is that the data can be seen by anyone looking at your browser and it can show up in the history. If you are sending sensitive information from your form, you shouldn't use this method.
POST is slightly different. Instead of encoding the form data into the URL, it is sent in a special data stream. This means that it is invisible in the browser, so is far more secure than GET (although sensitive information should still not be sent without encryption). By default a form will submit using GET unless you specify the method (although it is good practice to always specify whichever one you are using).
Usually form tags only ever include the method and action attributes, but occasionally you will need to use the name attribute. This is used as:
In practically every case you should use both the method and action tags when defining a form, and should only use name if you particularly need it.
The most basic type of form input is the standard textbox, like this:
It allows the user to enter text and will send this data to the processing script when the form is submitted. Nearly all input options use the same basic tag, which is the:
tag. This is combined with a number of attributes to provide different types of input on your form. To give a standard text box, you use the following:
This is not quite enough to have a working text box, though, as there is another inportant attribute, name. Name allows you to give the textbox a name with which the data can be referred to later. It should be entered without spaces or special characters, but it is important that each item on the form is given a different name. The name attribute is added as follows:
<input type="text" name="username">
Which names this textbox 'username'. As with many tags involved with HTML forms, this is an invisible change, and is only really of use once you start processing forms. If you are submitting your form using GET, though, the input's name will be shown in the URL of the page (it is also sent with the data if you use POST, but this is invisible), for example:
A third attribute which can be used with your textbox is value. This allows you to set an initial value for your textbox, which can be changed by the user, for example if I had a textbox to take in an e-mail address, I could set the inital value to 'email@example.com' by the following code:
<input type="text" name="email" value="firstname.lastname@example.org">
There are a few more attributes which can be used with textboxes, but they are not necessary for basic forms, so these will be covered in the next part.
More HTML In Forms
Although it is probably obvious, I will just mention that all other HTML tags are available to you inside your <form> tags. It is important to remember, for example, to label all your input elements, so that the user knows what to enter in them. You can use all other types of HTML formatting as well as text, though, and often the use of tables can help set out an HTML form in a better way.
Once you have got the user to enter some data into a form, however basic it may be, you will need some way for them to send it on to the next page. This is where buttons come in. There are two basic buttons available to you in HTML, submit and reset. Submit is the most commonly used. Basically, when you put in a submit button, a button will appear on the page which, when clicked, tells the browser to send the form data to the URL which you defined in the action part of the form tag, using the method you supplied. The most basic submit button is added using the following code:
There is an optional attribute of the submit button, tho