• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

How to perform / call CGI_LIB_PL.pl ?

I have an email form which contains the javascript (for user to pick email address) and I downloaded the perl script (CGI_LIB_PL.pl) for decoding the user input for the textarea.  I know the CGI_LIB_PL.pl is a standard perl lib which will perform the decoding.  

Additional Note:
1. What the /cgi-bin/CGI_LIB_PL.pl does is to convert the input from HTML format into whatever readable (If we do not use this perl script, it can't read some special char.  example: all spaces become +'s)

Problem:  See the document below.  When I use the email form to send out email, it just returned a CGI timeout page for me.  

1. Am I using the right way to call the CGI_LIB_PL.pl?  
2. Do I have to use an additional perl script to tell the CGI_LIB_PL.pl what to do?  If so, how?

Please see the following
    function doMail()
       // Reset each variable each time button is clicked

       // Next 4 if's check to see which addresses are checked
       if (document.email.email1.checked==1)
       if (document.email.email2.checked==1)
       if (document.email.email3.checked==1)
          if(checked1==true || checked2==true)
       if (document.email.email4.checked==1)
          if(checked1==true || checked2==true || checked3==true)

       // Alert message if no address is checked
          alert("\nYou must select an address from the list first.");



    <form name="email">
      <p><input type="checkbox" name="email1" value="cathy@aol.com">Cathy<br>
      <input type="checkbox" name="email2" value="123456@skytel.com">Email Pager<br>
      <input type="checkbox" name="email3" value="john@aol.com">John<br>
      <input type="checkbox" name="email4" value="KK@sfsu.edu">KK</p>

    <form method="post" action="/cgi-bin/CGI_LIB_PL.pl" name="mesgForm" onsubmit="doMail()">
      <p><textarea name="message" rows="5" cols="30"></textarea><br>
      <input type="reset" value="Reset Form"> <input type="submit" value="Send Message"> </p>
  • 2
1 Solution
cklhAuthor Commented:
Adjusted points to 50
cklhAuthor Commented:
This is the CGI_LIB_PL.pl script that I downloaded.....


#!/usr/local/bin/perl -- -*- C -*-
# Perl Routines to Manipulate CGI input
# S.E.Brenner@bioc.cam.ac.uk
# $Header: /cys/people/brenner/http/cgi-bin/RCS/cgi-lib.pl,v 1.8 1995/04/07 21:35:29 brenner Exp $
# Copyright 1994 Steven E. Brenner  
# Unpublished work.
# Permission granted to use and modify this library so long as the
# copyright above is maintained, modifications are documented, and
# credit is given for any use of the library.
# Thanks are due to many people for reporting bugs and suggestions
# especially Meng Weng Wong, Maki Watanabe, Bo Frese Rasmussen,
# Andrew Dalke, Mark-Jason Dominus and Dave Dittrich.
# For more information, see:
#     http://www.bio.cam.ac.uk/web/form.html       
#     http://www.seas.upenn.edu/~mengwong/forms/   
# Minimalist http form and script (http://www.bio.cam.ac.uk/web/minimal.cgi):
# require "cgi-lib.pl";
# if (&ReadParse(*input)) {
#    print &PrintHeader, &PrintVariables(%input);
# } else {
#   print &PrintHeader,'<form><input type="submit">Data: <input name="myfield">';
# ReadParse
# Reads in GET or POST data, converts it to unescaped text, and puts
# one key=value in each member of the list "@in"
# Also creates key/value pairs in %in, using '\0' to separate multiple
# selections
# Returns TRUE if there was input, FALSE if there was no input
# UNDEF may be used in the future to indicate some failure.
# Now that cgi scripts can be put in the normal file space, it is useful
# to combine both the form and the script in one place.  If no parameters
# are given (i.e., ReadParse returns FALSE), then a form could be output.
# If a variable-glob parameter (e.g., *cgi_input) is passed to ReadParse,
# information is stored there, rather than in $in, @in, and %in.
sub ReadParse {
  local (*in) = @_ if @_;
  local ($i, $key, $val);
  # Read in text
  if (&MethGet) {
    $in = $ENV{'QUERY_STRING'};
  } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
  @in = split(/&/,$in);
  foreach $i (0 .. $#in) {
    # Convert plus's to spaces
    $in[$i] =~ s/\+/ /g;
    # Split into key and value.  
    ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
    # Convert %XX from hex numbers to alphanumeric
    $key =~ s/%(..)/pack("c",hex($1))/ge;
    $val =~ s/%(..)/pack("c",hex($1))/ge;
    # Associate key and value
    $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
    $in{$key} .= $val;
  return length($in);

# PrintHeader
# Returns the magic line which tells WWW that we're an HTML document
sub PrintHeader {
  return "Content-type: text/html\n\n";

# MethGet
# Return true if this cgi call was using the GET request, false otherwise
sub MethGet {
  return ($ENV{'REQUEST_METHOD'} eq "GET");
# Returns a URL to the script
sub MyURL  {
  return  'http://' . $ENV{'SERVER_NAME'} .  $ENV{'SCRIPT_NAME'};
# CgiError
# Prints out an error message which which containes appropriate headers,
# markup, etcetera.
# Parameters:
#  If no parameters, gives a generic error message
#  Otherwise, the first parameter will be the title and the rest will
#  be given as different paragraphs of the body
sub CgiError {
  local (@msg) = @_;
  local ($i,$name);
  if (!@msg) {
    $name = &MyURL;
    @msg = ("Error: script $name encountered fatal error");
  print &PrintHeader;
  print "<html><head><title>$msg[0]</title></head>\n";
  print "<body><h1>$msg[0]</h1>\n";
  foreach $i (1 .. $#msg) {
    print "<p>$msg[$i]</p>\n";
  print "</body></html>\n";
# PrintVariables
# Nicely formats variables in an associative array passed as a parameter
# And returns the HTML string.
sub PrintVariables {
  local (%in) = @_;
  local ($old, $out, $output);
  $old = $*;  $* =1;
  $output .=  "<DL COMPACT>";
  foreach $key (sort keys(%in)) {
    foreach (split("\0", $in{$key})) {
      ($out = $_) =~ s/\n/<BR>/g;
      $output .=  "<DT><B>$key</B><DD><I>$out</I><BR>";
  $output .=  "</DL>";
  $* = $old;
  return $output;
# PrintVariablesShort
# Nicely formats variables in an associative array passed as a parameter
# Using one line per pair (unless value is multiline)
# And returns the HTML string.

sub PrintVariablesShort {
  local (%in) = @_;
  local ($old, $out, $output);
  $old = $*;  $* =1;
  foreach $key (sort keys(%in)) {
    foreach (split("\0", $in{$key})) {
      ($out = $_) =~ s/\n/<BR>/g;
      $output .= "<B>$key</B> is <I>$out</I><BR>";
  $* = $old;
  return $output;
1; #return true
It seems you missunderstand a bit the mechanism of CGI. A CGI-program is not executed on the client maschine like java-script, it runs on the web-server when you submit the form with action="/cgi-bin/myscript.pl".
The script "CGI_LIB_PL.pl" contains only some functions that helps you writing cgi-programs in perl. But you need to put them on your webserver into its cgi-bin directory.

You don't need the java-script, you have to write a cgi-program, which could use this CGI_LIB_PL.pl (I think name should be "cgi-lib.pl").
This library offers you some functions that parses the query-string and decodes data entered in your textarea.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now