Privacy Policy Cookie Policy Terms and Conditions Form (web) - Wikipedia, the free encyclopedia

Form (web)

From Wikipedia, the free encyclopedia

A webform on a web page allows a user to enter data that is, typically, sent to a server for processing and to mimic the usage of paper forms. Forms can be used to submit data to save on a server (e.g., ordering a product) or can be used to retrieve data (e.g., searching on a search engine).

Contents

[edit] XHTML/HTML forms

Sample form rendered by Mozilla Firefox. (Click on image to find the source HTML code that generated this form.)
Enlarge
Sample form rendered by Mozilla Firefox. (Click on image to find the source HTML code that generated this form.)

A form in XHTML or HTML is by far the most common way to use a form online.

The following are a list of elements that can make up the user-inputting portion a form:

  • input field
    • text – a simple text box that allows input of a single line of text
    • checkbox – a check box
    • radio – a radio button
    • submit – a button that tells the browser to take action on the form (typically to send it to a server)
  • textarea – much like the text input field except a textarea allows for multiple rows of data to be shown and entered
  • select – a drop-down list that displays a list of items a user can select from

These basic elements provide most possible graphical user interface (GUI) elements, but not all. For example, there are no equivalents to a combutcon, balloon help, tree view, or grid view. A grid view, however, can be mimicked by using a standard HTML table with each cell containing a text input element. A tree view could also be mimicked through nested tables.

The sample image on the right shows all of these elements:

  • a text box asking for your name
  • a pair of radio buttons asking you to pick your sex
  • a select box giving you a list of eye colors to choose from
  • a pair of check boxes to click on if they apply to you
  • a text area to describe your athletic ability
  • a submit button to send it to the server

[edit] Combined with programs

Forms can be combined with various scripting languages to allow developers to create dynamic web sites. This includes both client-side and/or server-side languages.

[edit] Client-side

The de facto standard client-side scripting language for web sites is JavaScript. Utilizing JavaScript on the Document Object Model (DOM) leads to the method of Dynamic HTML that allows dynamic creation and modification of a web page within the browser.

While client-side languages used in conjunction with forms are limited, they often can serve to do pre-validation of the form data and/or to prepare the form data to send to a server-side program.

[edit] Server-side

Server-side programs can do a vast assortment of tasks to create dynamic web sites — from authenticating a login through, for example, Lightweight Directory Access Protocol to retrieving and storing data in a database to spell checking to sending e-mail — quite unlike client-side programs. Most (all?) server-side program requests must pass through the web server's Common Gateway Interface to execute the program to actually perform the tasks.

The advantage of server-side over client-side is the concentration of functionality onto one computer (the server) instead of relying on each web browser implementing all of the various functions the same. This very problem is quite evident to any developer who writes JavaScript code for multiple browsers.

Scripting languages are the most common server-side programs used for web sites, but it is also possible to run compiled programs.

Some of the scripting languages commonly used:

Some of the compiling languages commonly used:

[edit] PHP

PHP is one very common language used for server-side languages used and is one of the few languages created specifically for server-side programs.

A PHP script may:

  • display the information on another page (ex: asking for a user's name and then displaying it on the web page)
  • act as a log on interface
  • post the data to a database (ex: mySQL, an ASCII file, etc.)
  • store the information on the viewer's computer in an HTTP cookie
  • generate an e-mail, either using the data or including said data in the e-mail's contents (possibly as an e-mail attachment)

The HTML form learns to where it shall pass the data from the action attribute of the form's HTML element. The target PHP file then retrieves the data either through POST or GET (see HTTP for more information), depending on the programmer's preference. Here is a basic form handler PHP script that will post the form's contents, in this case "user", to the page using POST:

form.html

<html>
<body>
 <form action="form_handler.php" method="get">
   User Name: <input name="user" type="text">
   <input type="submit">
 </form>
</body>
</html>

form_handler.php

<html>
<body>
<?php
 /* 
  * This will print whatever the user put into the form on the form.html page.
  */

 $name = $_GET['user'];
 echo "Hello, ". $name ."!";
?>
</body>
</html>

[edit] Perl

Perl is another language often used for web development. Perl scripts are traditionally used as Common Gateway Interface applications (CGIs) toward that end. In fact, Perl is such a common way to write CGIs that the two are often confused. CGIs may be written in other languages than Perl (compatibility with multiple languages is a design goal of the CGI protocol) and there are other ways to make Perl scripts interoperate with a web server than using CGI (such as FastCGI or Apache's mod perl).

Perl CGIs were once a very common way to write web applications. But not being specifically designed for web development, Perl is now often viewed as less practical (both for developers and users) than specialized languages like PHP or ASP for that purpose, especially if Perl modules (some common ones being written in C) would need to be installed on the web host or if wanting to use a non-CGI environment that might require extra configurations on the web server. Some web hosts also rely on interpreter-level sandboxing, which while possibly doable with the Safe module, wouldn't be very practical and undoubtly break a lot of scripts considering common practices. Similar considerations might apply to other general-purpose scripting languages like Python or Ruby. For these reasons, a lot of cheap web hosts nowadays effectively only support PHP and web developers often seek compatibility with them.

A modern Perl 5 CGI using the standard CGI module with a form similar to the one above might look like:

form_handler.pl

#!/usr/bin/env perl

my $cgi = do { use CGI; new CGI; };

print $cgi->header ( 
  -content_type => 'text/html'
);

my $name = $cgi->escapeHTML($cgi->param('user'));

print qq{
  <html>
  <body>
    <p>Hello, $name!</p>
  </body>
  </html>
};

[edit] Form-to-email scripts

Among the simplest and most commonly needed types of server-side script is that which simply emails the contents of a submitted form. This kind of script is frequently exploited by spammers, however, and many of the most popular form-to-email scripts in use are vulnernable to be hijacked for spamming purposes. One of the most popular scripts of this type was "FormMail.pl" made by Matt's Script Archive. Today, no version of this still frequently used script is considered secure.

More recent and secure scripts for emailing submitted forms include Jack's FormMail.php and nms formmail. In addition, remote hosting of form to email scripts by very secure servers is an increasingly popular alternative.

[edit] XForms

Further information: XForms

[edit] See also

[edit] External links

In other languages
THIS WEB:

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - be - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - closed_zh_tw - co - cr - cs - csb - cu - cv - cy - da - de - diq - dv - dz - ee - el - eml - en - eo - es - et - eu - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gd - gl - glk - gn - got - gu - gv - ha - haw - he - hi - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mg - mh - mi - mk - ml - mn - mo - mr - ms - mt - mus - my - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - rm - rmy - rn - ro - roa_rup - roa_tara - ru - ru_sib - rw - sa - sc - scn - sco - sd - se - searchcom - sg - sh - si - simple - sk - sl - sm - sn - so - sq - sr - ss - st - su - sv - sw - ta - te - test - tet - tg - th - ti - tk - tl - tlh - tn - to - tokipona - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Static Wikipedia 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2007:

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - be - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - closed_zh_tw - co - cr - cs - csb - cu - cv - cy - da - de - diq - dv - dz - ee - el - eml - en - eo - es - et - eu - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gd - gl - glk - gn - got - gu - gv - ha - haw - he - hi - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mg - mh - mi - mk - ml - mn - mo - mr - ms - mt - mus - my - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - rm - rmy - rn - ro - roa_rup - roa_tara - ru - ru_sib - rw - sa - sc - scn - sco - sd - se - searchcom - sg - sh - si - simple - sk - sl - sm - sn - so - sq - sr - ss - st - su - sv - sw - ta - te - test - tet - tg - th - ti - tk - tl - tlh - tn - to - tokipona - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Static Wikipedia 2006:

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - be - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - closed_zh_tw - co - cr - cs - csb - cu - cv - cy - da - de - diq - dv - dz - ee - el - eml - en - eo - es - et - eu - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gd - gl - glk - gn - got - gu - gv - ha - haw - he - hi - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mg - mh - mi - mk - ml - mn - mo - mr - ms - mt - mus - my - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - rm - rmy - rn - ro - roa_rup - roa_tara - ru - ru_sib - rw - sa - sc - scn - sco - sd - se - searchcom - sg - sh - si - simple - sk - sl - sm - sn - so - sq - sr - ss - st - su - sv - sw - ta - te - test - tet - tg - th - ti - tk - tl - tlh - tn - to - tokipona - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu