Although CGI can invoke any program, the CGI Perl module18 can be used to simplify parsing of the query string containing user input parameters and sending the HTTP request back to the browser. (Rather than the Apache module that I mentioned above this is a Perl module to make CGI programming easier.) One of the central aspects of this web application is displaying and processing forms. Here is an example of a Perl script that displays a group of three radio buttons and processes the result of the user's selection. You can try the script out at radio_example.pl.
Here is an example of the RNA translation script described above converted into a CGI program to display a HTML interface to translate RNA to an amino acid sequence. The page can be tried out at translate_form.pl.
The web page Translation of DNA to an Amino Acid Sequence on this site was constructed using these principles.
The use CGI; line tells the Perl interpreter that the
script will be using the CGI module. The $query object is used to
output the HTTP header, test for the existence of the input parameter
'rna' ($query->param('rna')), and
create the text area for entering the RNA string. In the else
stanza the algorithm for translating the RNA sequence to amino acids is
executed, as described in the example in the Perl
section of this article.
The script demonstrated use of a text area. Another common form element is a textfield, which is generated with script in the form
In this method the first parameter is the name of the textfield, the second is the default value, the third is the length of the textfield as shown on the HTML form, and the forth parameter is the maximum number of characters accepted by the form.
In the code that repeats the input string back to the user there is no checking for validity, including escaping of HTML. This is only acceptable in this example because I am repeating the user's input data to him or herself. If the input data was stored in a database and output as HTML to someone else this is vulnerable to a cross-site scripting attack. In that case the user entering the data could include <script> tags to attack the user viewing the data. The script in between the <script> would be executed in the browser of the user viewing the data.
There are no user comments.
Please send ideas and opinions by email at alexamies@gmail.com.