Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


How to perform / call CGI_LIB_PL.pl ?

Posted on 1998-12-20
Medium Priority
Last Modified: 2010-03-05
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>
Question by:cklh
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 1207034
Adjusted points to 50

Author Comment

ID: 1207035
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

Accepted Solution

Thomy earned 200 total points
ID: 1207036
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question