CGI Forms   «Prev  Next»

Lesson 1

Perl CGI and Forms

This module is a thorough introduction to CGI and discusses how a CGI program interfaces with the Web server, how it communicates with the Web client or browser. Some of the concepts introduced in this module are:
  1. The GET and POST methods
  2. Form data-encoding
  3. The query string
  4. Form elements, or widgets

When you are done with this module, you should have a good understanding of how Web forms work and how to interact with them using CGI.
The training server has been set up so that each user has their own web space underneath their home directory. All files which will be accessible via the web should be placed in the directory named public_html. This is common for most personal homepages. The directory ~username/public_html on the Unix file system maps to the
URL http://hostname/~username/ 

when using Apache Server with the Unix Operating system.
via the web. Replace username with your username.


How "Form data-encoding" is used with Perl-CGI Web programming

Form data encoding is used with Perl-CGI (Common Gateway Interface) web programming to transmit data from an HTML form to a Perl script on the server. The data encoding method specifies how the form data is formatted and sent to the server. This allows the script to access and process the data entered into the form.
Here are the commonly used form data encoding methods in Perl-CGI:
  1. application/x-www-form-urlencoded: This is the default encoding method used by HTML forms. It encodes the form data as key-value pairs, separated by ampersands (&) and equal signs (=). For example, if a form has two fields, "name" and "email," the encoded data might look like this:
    name=John%20Doe&email=johndoe@example.com
    
  2. multipart/form-data: This encoding method is used when uploading files through HTML forms. It allows the form to send both text data and binary data (such as images or videos) to the server. Each field in the form is represented as a separate part, with its own headers and data.
  3. application/json: This encoding method is used to send JSON (JavaScript Object Notation) data to the server. JSON is a popular data format for exchanging data between web applications. It encodes data as a hierarchical structure of key-value pairs, arrays, and objects.

To use form data encoding in a Perl-CGI script, you can use the following steps:
  1. Import the CGI module:
    use CGI;
    
  2. Create a CGI object:
    my $cgi = new CGI;
    
  3. Use the CGI object's `param()` method to access the form data. The `param()` method takes the name of the form field as an argument and returns the value of that field. For example, to access the value of the "name" field, you would use the following code:
    my $name = $cgi->param('name');
    

You can then use the value of the form field in your Perl script to process the data as needed. By using form data encoding, you can easily collect and process data from HTML forms in your Perl-CGI web applications.

SEMrush Software

Web Programming

The Internet is the most important source of bioinformatics data. From FTP sites to web-enabled programs, the Perl programmer who is literate in bioinformatics needs to be able to access web resources. Just about every lab has to have its own web page these days, and many grants even require it. You will need to learn the basics about the HTML and XML markup languages that display web pages, about the difference between a web server and a web browser, and javadeploy.com provides you with all the information that you need.
The popular CGI.pm module makes it fairly easy to create interactive web pages, and several other modules are available that make Internet programming tasks relatively easy. For instance, you can write code for your own web page that enables visitors to try out your latest sequence analyzer or search through your special-purpose database. You can also add code to your own programs to enable them to interact with other web sites, querying and retrieving data automatically. Collaborators who are geographically diverse can use such web programming to work cooperatively on a project, whether you are in Brazil or Russia.