- Form (web)
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 asearch engine ).XHTML/HTML forms
A form in
XHTML orHTML is by far the most common way to use a form online.The following elements can make up the user-inputting portion of a form:
* input field
** text – a simpletext box that allows input of a "single" line of text
** checkbox – acheck box
** radio – aradio button
** file – afile select control for uploading a file
** reset – areset button that, when activated, tells the browser to restore the values to their initial values.
** 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 – adrop-down list that displays a list of items a user can select fromThe sample image on the right shows all of these elements:
* atext box asking for your name
* a pair ofradio button s asking you to pick your sex
* a select box giving you a list of eye colors to choose from
* a pair ofcheck box es to click on if they apply to you
* a text area to describe your athletic ability
* a submit button to send it to the serverThese basic elements provide most possible
graphical user interface (GUI) elements, but not all. For example, there are no equivalents to acombo box ,balloon help ,tree view , orgrid 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 or, more semantically appropriately, nested lists.Many of these are available through JavaScript libraries.Combined with programs
Forms can be combined with various
scripting language s to allow developers to create dynamicweb site s.This includes both client-side and/or server-side languages.Client-side
The
de facto standard client-side scripting language for web sites isJavaScript .Utilizing JavaScript on theDocument Object Model (DOM) leads to the method ofDynamic 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.erver-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 adatabase to spell checking to sendinge-mail — quite unlike client-side programs.Most server-side program requests must pass through theweb server 'sCommon 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 writesJavaScript code for multiple browsers.Scripting language s 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:
*PHP
*Perl
* ASP
*ASP.NET
*Adobe ColdFusion
* JSPSome of the compiling languages commonly used:
* C
*C++
* C#
* JavaPHP
PHP is one very common language used for server-side languages 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 logon interface
* post the data to a database (ex:mySQL , anASCII file, etc.)
* store the information on the viewer's computer in anHTTP cookie
* generate ane-mail , either using the data or including said data in the e-mail's contents (possibly as ane-mail attachment )The HTML form learns where to 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 (seeHTTP for more information), depending on theprogrammer '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 GET:form.html
form_handler.php
In the above script the $_GET [
" ] and $_POST [" ] commands need to be changed, depending on what is used in the form, however $_REQUEST [" ] is used for both so it is more efficient to use for form collection.Perl
Perl is another language often used forweb development . Perl scripts are traditionally used asCommon Gateway Interface applications (CGIs). 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 aweb server than using CGI (such asFastCGI or Apache'smod 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 likePHP or ASPFact|date=March 2008. This is especially true ifPerl module s would need to be installed on theweb 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 possible with the [http://perldoc.perl.org/Safe.html Safe module] , wouldn't be very practical and undoubtly break a lot of scripts considering common practices.Fact|date=March 2008 Similar considerations might apply to other general-purpose scripting languages like Python or Ruby.Fact|date=March 2008 For these reasons, a lot of cheap web hosts nowadays effectively only support PHP and web developers often seek compatibility with them.Fact|date=March 2008A modern Perl 5 CGI using the standard CGI module with a form similar to the one above might look like:
form_handler.pl
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
spammer s, however, and many of the most popular form-to-email scripts in use are vulnerable to be hijacked for spamming purposes. One of the most popular scripts of this type was [http://www.scriptarchive.com/formmail.html "FormMail.pl"] made by Matt's Script Archive. Today, no version of this still frequently used script is considered secure.To avoid the confusion and difficulty of installing and using scripts, webmasters often use a free forms processing service to get their forms working.
XForms
External links
* [http://www.w3.org/TR/html4/interact/forms.html Forms in HTML documents] , the
W3C 's spec page for forms in HTML 4.
Wikimedia Foundation. 2010.