Flux rss

HTML forms

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  
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.

Résultats pour HTML forms

Outlook issue with HTML form 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
How to view emal messages sent in HTML Hello, 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
HTML Posting Form Hi, guys! I'm trying to figure out how to post data from an HTML form to an HTML. I don't know if I'm very clear but, basically, I want to create an easy way for multiple, non-coders to add information to a webpage. The HTML form will... en.kioskea.net/forum/affich-246-html-posting-form

Résultats pour HTML forms

How to create your own WebsiteHow to create your own Website What is HTML? Example 1: HTML Tags HTML Elements Basic HTML Tags to Remember Example 2 HTML Attributes and Values Example 3 Colour Tags Example 4 Text Formatting Example 5 HTML Division Tags Example... en.kioskea.net/faq/sujet-173-how-to-create-your-own-website
Formatting Your Hard DriveFormatting Your Hard Drive Formatting and installing your Hard drive using the installation CD ] A hard disk drive is a non-volatile device mainly for data storage. Usually faster than any other storage device, this essential... en.kioskea.net/faq/sujet-194-formatting-your-hard-drive
Formatting your Flashdisk (USB Key )Formatting your Flashdisk (USB Key) How to format your USB Key? It is compulsory to format your USB Key regularly if you are frequently performing File transfer to one computer to another. Your computer can get infected with potential... en.kioskea.net/faq/sujet-186-formatting-your-flashdisk-usb-key

Résultats pour HTML forms

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... en.kioskea.net/forum/affich-307-adobe-flash-form
HTML Code "mailto:_____" issuesI am having an issue with the HTML "mailto:____" form code. Essentially, I want an extensive form on my site to be filled out and sent using only html forms, as I've been struggling with formmail.pl and cgi for a while; there must be a simpler... en.kioskea.net/forum/affich-7926-html-code-mailto-issues
Can we return to server while sesHello, Can anybody advice me at what extent we can replace javascript with PHP ?. can we pick value from html form to PHP without form submission ? if we can than how ? en.kioskea.net/forum/affich-6270-can-we-return-to-server-while-ses

Résultats pour HTML forms

Download LiveProject Free Project ViewerLiveProject is an application of visualization of file mpp free. LiveProject introduces no degradation of the file mpp during exportation in format Excel or html. With LiveProject, you will be able to print your own documents. The use of LiveProject... en.kioskea.net/telecharger/telecharger-860-liveproject-free-project-viewer
Download Smartision ScreenCopysmartision ScreenCopy is a (free) free software allowing to accomplish easily captures of screen on formats JPEG or BMP. It has on top of that an interesting functionality of creation of galleries photographs in format HTML. Features Saving... en.kioskea.net/telecharger/telecharger-316-smartision-screencopy
Download CVitaeCvitae is a sim pl e tool but efficient for the writing of your CV. It ca do the layout in word format or HTML. During the different stages of the cration of your cv, you ca select its presentation from numerous models and /or follow the advice... en.kioskea.net/telecharger/telecharger-1130-cvitae

Résultats pour HTML forms

HTML - Special characters HTML standards require all code to be written in 7-bit ASCII, which means that accented characters are not allowed. Despite this, current browsers recognise accented characters; you can enter accented characters directly in your text editor, but your... en.kioskea.net/html/htmlcarac.php3
HTML - Images Having a few images on a website can make it more attractive and user-friendly. However, it is important not to go overboard, since images can take a long time to load, and in some cases can make a document harder to read. The IMG tag is used for... en.kioskea.net/html/htmlimages.php3
HTML - Markups 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, images, etc. The use of these... en.kioskea.net/html/htmlbalise.php3