Flux rss
Bookmark Bookmark & Share
I formulari HTML Os formulários HTML Die HTML-Formulare Les formulaires HTML Formularios HTML

Forms

Interactive forms let web page authors give their pages interactive elements, such as for receiving messages from their readers, much like the reply cards found in some magazines.

The reader enters information by filling in fields or clicking on buttons, then pressing a submit button to send it to a URL, normally one pointing to an e-mail address or to a dynamic web script like PHP, ASP, or a CGI script.

The FORM tag

Forms are delimited with the <FORM> ... </FORM> tag, which contains several form elements, such as buttons and text boxes, and which must possess the following attributes:

  • METHOD indicates how replies will be sent
    "POST" is the value that sends the data to the processing agent by storing it in the body of the form, while "GET" sends the data by adding it to the URL, separating it from the address with an exclamation mark (to learn more about the POST and GET methords, consult the article on HTTP protocol)
  • ACTION indicates the address that the information will be sent to (a CGI script or e-mail address (mailto:email.address@machine))
An optional attribute of the FORM tag is ENCTYPE, which specifies how the form data is encoded in the URL. However, this does not need to be specified, since the default value (application/x-www-form-urlencoded) is the only legal value. The optional attribute ACCEPT is used to set MIME types for the data which the form can send.

This is the syntax for the FORM tag:

<FORM METHOD="POST" or "GET" ACTION="url" ENCTYPE="x-www-form-urlencoded">
...
</FORM>

Here are a few examples of FORM tags:

<FORM METHOD=POST ACTION="mailto:webmaster@kioskea.net">

<FORM METHOD=GET ACTION="http://en.kioskea.net/cgi-bin/script.cgi">

Inside the FORM Tag

The FORM tag acts as a sort of container for storing elements which let the user select or enter data. All data will be sent to the URL indicated in the ACTION attribute of the FORM tag by the method indicated by the METHOD attribute.

Any basic HTML element may be inserted into a FORM tag (such as text, buttons, tables, and links), but the interactive elements are the most important. These interactive elements are:

  • The INPUT tag: All buttons and text boxes
  • The TEXTAREA tag: A text box
  • The SELECT tag: A multiple-choice list

Sending Data

When a form is submitted (by clicking on the submit button), the data in the form is sent to a CGI script in the form of name/value pairs, which are sets of data represented as the name of the form element, an equal sign ("="), and then the associated value. These name/value pairs are set off from one another by ampersands ("&"). So the data sent to the script will look like this:

field1=value1&field2;=value2&field3;=value3
With the GET method (sending data using a URL), the URL will be a string that looks like this:

http://en.kioskea.net/cgi-bin/script.cgi?field1=value1&field2;=value2

The INPUT Tag

The INPUT tag is the essential form tag, since it is used to create many interactive "elements." This tag's syntax is as follows:

<INPUT type="Field Name" value="Default Value" name="Element Name">
The name attribute is essential, as it lets the CGI script know which field is associated with which name/value pair, meaning that the name of the field will be followed by an equal sign ("=") followed by the value entered by the user, or if the user didn't input a value, by the default value for the value attribute.
The type attribute is used to specify which type of element is represented by the INPUT tag. These are the possible values:
  • checkbox: Checkboxes can be in one of two states: checked or unchecked. When the box is checked, the name/value pair is sent to the CGI.
  • hidden: This field, which the browser does not display, is for defining a fixed setting that will be sent to the CGI as a name/value pair.
  • file: A field that lets the user specify a filepath leading to a file that will be sent along with the form. The file types that can be sent should be specified, by using the ACCEPT attribute of the FORM tag
  • image: A customised submit button, which appears as whatever image is at the location defined by its SRC attribute
  • password: A textbox, in which the characters that are entered show up as asterisks, in order to camouflage the input text.
  • radio: A button allowing the user to choose from between several options. Each of these radio buttons must have the same name attribute. The name/value pair of the radio button selected will be sent to the CGI. Using the checked attribute for one of the buttons lets you define it as being selected by default.
  • reset: A reset button for clearing all elements in the form by setting them back to their default values.
  • submit: A submit button to send the form. The text on the button can be set using the value attribute.
  • text: A textbox for entering a line of text. The size of the box may be defined using the size attribute and the maximum length of the text with the maxlength attribute.

The TEXTAREA tag

The TEXTAREA tag is for defining a textbox bigger than just the single line allowed by the INPUT tag. This tag has the following attributes:

  • cols: represents the number of characters that a line may contain
  • rows: represents the number of lines
  • name: represents the name associated with the textbox, which allows it to be identified in the name/value pair.
  • readonly: prevents the user from changing the default text in the field
  • value: represents the default value that will be sent to the script if the user has not entered anything in the textbox

The SELECT tag

The SELECT tag is for creating a dropdown list of elements (specified by the OPTION tags within it). This tag's attributes are:

  • name: represents the name associated with the textbox, which allows it to be identified in the name/value pair.
  • disabled: creates a disabled list, shown as being grayed out
  • size: represents the number of lines in the list (this value may be larger than the number of actual elements in the list)
  • multiple: enables the user to select several fields in the list

Example Form

Forms can be placed in a page using tables (recommended for a professional-looking layout). Here is an example summing up the above points, showing you how to place a form in a web page using a table:

<FORM method=post action="cgi-bin/script.pl">
User Registration
<TABLE BORDER=0>
<TR>
<TD>Last Name</TD>
<TD>
<INPUT type=text name="lastname">
</TD>
</TR>

<TR>
<TD>First Name</TD>
<TD>
<INPUT type=text name="firstname">
</TD>
</TR>

<TR>
<TD>Gender</TD>
<TD>
Man: <INPUT type=radio name="gender" value="M">
<br>Woman: <INPUT type=radio name="gender" value="F">
</TD>
</TR>

<TR>
<TD>Occupation</TD>
<TD>
<SELECT name="occupation">
<OPTION VALUE="teacher">Teacher</OPTION>
<OPTION VALUE="student">Student</OPTION>
<OPTION VALUE="engineer">Engineer</OPTION>
<OPTION VALUE="retired">Retired</OPTION>
<OPTION VALUE="other">Other</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TD>Comments</TD>
<TD>
<TEXTAREA rows="3" name="comments">
Type your comments here</TEXTAREA>
</TD>
</TR>

<TR>
<TD COLSPAN=2>
<INPUT type="submit" value="Send">
</TD>
</TR>
</TABLE>
</FORM>

Here's what shows up on screen:

User Registration
Name
First Name
Gender Man:
Woman:
Occupation
Comments

FORM Tag Attributes and Types of Input

Tag Attribute Value Result Visual Effect
<FORM> ... </FORM> METHOD POST
GET
   
ACTION   Sends to the address shown  
ENCTYPE   Specifies encoding type  
<INPUT> TYPE submit performs the ACTION in the <FORM> tag
text simple line of text whose length
is given by the SIZE attribute
reset Erases the form's contents
radio radio button
checkbox checkbox
NAME   Name  
SIZE   Text size  
<TEXTAREA> ... </TEXTAREA> NAME   Text box
ROWS  
COLS  
<SELECT>

<OPTION> ... </OPTION>

</SELECT>

NAME    
MULTIPLE   Multiple selections possible
<OPTION> ... </OPTION> SELECTED Default choice  
VALUE Forced value  


Last update on Thursday October 16, 2008 02:43:14 PM.This document entitled « HTML forms » from Kioskea (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the licence, as this note appears clearly.
Outlook issue with HTML form (Solved) Hello, I have a small website with a very simple HTML form that allows user to send his data; then the webmaster receives an email with the data included in the form. My problem is that, when ever Outlook is set up on a machine, the email button open... en.kioskea.net/forum/affich-247-outlook-issue-with-html-form
HTMl form data into notepad in specific form. Hello, what I actually need is, a simple application to store the entered data in the html form into a text file like notepad. for eg: If I entered the user id and name in the html form, I want the user id and the name to be sent to a text file (note... en.kioskea.net/forum/affich-45458-html-form-data-into-notepad-in-specific-form
When message changes from text to HTML format Hi, Environment: My outlook 2003 default format is HTML. The Default fond for new/reply messages is Arial. The Problem: I get a message in text format. When I manually change the format of this message to HTML, the font of the message is Times Roman.... en.kioskea.net/forum/affich-63906-when-message-changes-from-text-to-html-format
Javascript - Delete a field of a form when clicking (focus)Delete a field from an Html form when clicking (focus) It is certainly happened to fall on an HTML form with values pre-filled for example describing the type of expected value. Though it may be useful under certain circumstances, if you have... en.kioskea.net/faq/sujet-1824-javascript-delete-a-field-of-a-form-when-clicking-focus
Online Forms - The input fieldsOnline Forms-The input fields What type of Data will lyou use The organization of fields Separate fields The organization of fields and titles Field length What type of Data will lyou use On most forms, all the information are not... en.kioskea.net/faq/sujet-2200-online-forms-the-input-fields
How to easily display PHP/HTML codes in your webpagesHow to easily display PHP/HTML codes in your webpages What code to use? If you want your visitors to be able to see the source codes of your webpage, there is a very easy way to do so. Normally, all you have to do in a HTML file using... en.kioskea.net/faq/sujet-824-how-to-easily-display-php-html-codes-in-your-webpages
How to view emal messages sent in HTMLHello, How can I veiw email messages sent in HTML format? I am receiving text only, but no pictures. I am using Outlook 2003 for my emails. Some of the newsletters I receive only show text, but no pictures or links. What setting do I need to change to... en.kioskea.net/forum/affich-10766-how-to-view-emal-messages-sent-in-html
How to show aspx to html format?Hello, I have one question,would you pay attention and help me?! I'm a web site designer and I'm working in Asp.net. I visited a web site yesterday and I saw all pages of this site is in html format. that site was dynamic but I couldn't see any .aspx... en.kioskea.net/forum/affich-105836-how-to-show-aspx-to-html-format
Adobe Flash Form?Hi, guys! I'm trying to learn how to create forms in Adobe Flash, mainly because working with spacing and all that junk with HTML forms is so boring - also because it might just be a way around using forms on MySpace. I've read a few tutorials on... en.kioskea.net/forum/affich-307-adobe-flash-form
Download HP USB Disk Storage Format ToolHP USB Disk Storage Format Tool is a small utility allowing to format a key USB or READER MP4. It also allows to make a key (Bootable). This software works with all keys and readers MP4 of the market. To make work this utility under Windows... en.kioskea.net/telecharger/telecharger-127-hp-usb-disk-storage-format-tool
Download HDD Low Level Format ToolIt is administrator's free application of hard disk. It is quick and easy to use. He allows to format and of partition discs including flash.It supports discs: SATA, IDE, S-ATA (SATA), IDE (E-IDE), SCSI, USB, FIREWIRE, LBA-48 and even the external... en.kioskea.net/telecharger/telecharger-815-hdd-low-level-format-tool
Download Format FactoryFormat Factory is an application that allows conversion of various types of media files. It has various characteristics that allow you to customize a lot of stuff like: Convert video formats, audio and picture shows. Repair damaged files. Reduce... en.kioskea.net/telecharger/telecharger-3532-format-factory
Pantone PANTONE Formula Guide Coated/Uncoated/MatteDesigners Formula Guide. Basic tools for accurate selection, specification and matching of solid PANTONEî colours. Eliminate guesswork with this industry standard. Three-guide set on coated, uncoated and matt stock. Includes 1, 114 solid PANTONEî... en.kioskea.net/guide/578343190-pantone-pantone-formula-guide-coated-uncoated-matte
Databases - Using formsUsing forms In order to use databases, the user must be provided with an interface that allows him or her to view data based on certain criteria. There is a tool for this: forms. A form is an interface with components for displaying, entering, or... en.kioskea.net/contents/bdd/bddform.php3
HTML MarkupHTML, A Markup Language HTML is not a programming language. Rather, it is used for describing the layout and format of content, written in the form of simple text. An HTML page is a basic text file containing tags for specifying text format,... en.kioskea.net/contents/html/htmlbalise.php3
HTML document layoutHTML document An HTML page is a simple file containing text formatted with HTML tags. Traditionally, the file is given an .htm or .html extension, but a web page may have other extensions as well. A web page can be built from even the most basic... en.kioskea.net/contents/html/htmldocument.php3