XHTML forms are primarily used to gather user input data and send it to scripts (programs) running on a web server. There are several ways in which this can be achieved, from the old but still good Common Gateway Interface (CGI) to the new environments such as ASP, PHP, JSP, ASP.NET. Regardless of the server side programming environment to sequence of operation is much the same.
This is much the same as the CGI diagram above except the PHP script executes within the process space of the HTTP server. With an Apache HTTP server PHP may be configured to run as either a server module or as a CGI script.
The HTML <form> tag has three attributes that control the interaction of the form with the program on the server:
For XHTML validity the <form> tag must be outside any container but the various form elements must be inside a container such as a paragraph or table.
<form action="/~mk05/cgi-bin/form.pl" method="get" enctype="application/x-www-form-urlencoded"> <p> Form components </p> </form>
This form demonstrator is a simple static HTML page that demonstrates several important concepts in the use of forms and the development of stateful web applications. Information is transmitted from this page to server side scripts in several ways. When the POST form to info.php link is clicked data is passed to the server side script info.php as a combination of GET, POST and cookie data.
Cookies are an important mechanism for implementing stateful web applications. This page demonstrates other ways of storing state information. State may be stored visibly as default values in form text fields and as default selects for checkboxes, radio buttons and options. State may be concealed in hidden form fields. And what about those GET parameters? This means of storing state is often referred to as URL re-writing. If this page were dynamically generated by a CGI program or server side script then all of these provide possible storage mechanisms for state.
HTML5 extends the range of form input types providing a richer widget set and inherent client side validation of user input.