Interactivity! What? And How?
Initially, there was a network, then e-mail appeared, and people began to correspond. They wanted to tell about themselves, share information – the World Wide Web (WWW) appeared. But static pages are just static pages … and then interactivity appeared!
First, let’s define the terminology. By interactive pages, I mean those that implement an interface with some program running on the server side. The form on the web page receives some data from the user, and the browser passes it to the web server, which launches the desired program. After the request has completed, the program returns the result to the web server, and it forms an HTML page on the fly and sends it back to the browser.
So what can we do using interactivity? The most famous thing that comes to mind is counters, guest books, forwarders, online stores, and database interfaces. In practice, anything can be done. It all depends on the skill of the programmer.
How is this done technically? And here’s how – on the server side, we place the necessary programs, databases, .. and configure the web server so that it can transfer user requests from the network to the processing program and get the result from it. This is done through the CGI protocol – Common Gateway Interface (which in Russian sounds like a “common gateway interface”). CGI is a set of rules by which a server passes a request to a program. Any program written in such a way as to satisfy these requirements can be used on a Web server.
Thus, interactive pages can be divided into two parts: form and program. In the form, we need to correctly describe all the elements of the interface and indicate the path to the program being executed. As you can see, everything is not so complicated. But what if you are not a programmer, but you need a simple program? In this case, you can use the archive of ready-made scripts, most of which are free. All typical tasks have long been resolved and debugged. These are guest books, counters, mailing lists, etc. You just need to find the right one and carefully read the description for it. After that, it remains only to correctly place the elements in the form and specify specific parameters for this script. More complex programs already have to be written by programmers with sufficient experience to do this.
Let’s look at a typical example – sending a form by mail. To do this, we will use the ready-made program from the Matt Wright archive, designed to send the contents of the form by mail – FormMail. This script needs to be configured and placed on the web server in a special directory where the CGI programs are located. Usually it is called cgi-bin (for confidence, consult with your provider – does it provide services for hosting CGI scripts, and what is the name of the directory for hosting scripts). And on the page – describe the form. Thus, we need to prepare two files: create an HTML form and configure a Perl script for our needs.
Let’s start with the form. The description of the form will be between the <form> and </form> tags and contain the form elements inside. We will make the most minimalist version of the form sender, which will contain the following fields: name, email address, message text. The HTML code of our page is as follows:
<head> <title> Email form </title> </head>
<form name = “Request” action = “/ cgi-bin / formmail.pl” method = “post”>
<input type = hidden name = “recipient” value = “firstname.lastname@example.org”>
<input type = hidden name = “subject” value = “Request for information”>
Your Name: <br>
<input type = text name = “Name”> <br>
<input type = text name = “E-mail”> <br>
<textarea name = “Message”> </textarea> <br> <br>
<input type = submit value = “Send”>
<input type = reset value = “Clear”>
A bit of clarification on the above code. Pay attention to the action parameter in the <form> tag – it defines the address of our script (.pl is the standard extension for programs written in PERL). The first elements in the form are special hidden fields for transmitting information to the script: the recipient field defines the e-mail to which we want to send the contents of the form.