[WEB4LIB] Need help with coding for online form

Catherine Buck Morgan catherine at leo.scsl.state.sc.us
Wed Dec 15 14:15:57 EST 1999


I've attached the parsing program, as Roy suggested. I noticed that
there are three different commands dealing with how the text should be
wrapped.... The form that I'm having problems with is the Information
Request Form. 

Thanks.

Roy Tennant wrote:
> 
> Catherine,
> Frankly, I doubt it is your form markup that is the problem -- it is much
> more likely to be the program that parses the form input, which no one
> will be able to debug unless you post it. Thanks,
> Roy
> 
> On Wed, 15 Dec 1999, Catherine Buck Morgan wrote:
> 
> > We have an intermittent problem with an online request form. Usually all
> > the text typed into the request text box comes across, but a couple of
> > times a week we will get a request with the text abruptly abbreviated.
> > Sometimes we only get the first line, sometimes we'll get two or three
> > lines, and then it stops. It's been very frustrating for our ILL people,
> > and I can't tell you how frustrating it's been for me!!! The code looks
> > good.
> >
> > The page is at http://www.state.sc.us/scsl/scln/ill/info.html. I've
> > copied the code below. I've indicated the problem box with some ***.
> > Thanks very much!!
> >
> >
> > <html>
> > <head>
> > <title>SCLN Inter-Library Loan Service - Information Request
> > Form</title>
> > </head>
> > <body>
> > <table>
> > <tr><td width=120><img align=left
> > src="/scsl/scln/ill/blue6.gif"></td><td width=420><center><h2>South
> > Carolina Library Network<br>Inter-Library Loan Service<br>Information
> > Request
> > Form</h2></center></td></tr></table>
> > <hr>
> >
> > <p>Use this form to request information from the State Library on
> > subjects of interest to your patrons.  Be as detailed as possible in
> > describing the information requested, and how it will be used (e.g. for
> > personal interest, term paper, etc.).  Identifying the age level (adult
> > or student) of the patron and sources previously checked will help us to
> > supply appropriate materials.</p>
> >
> > <p>Providing as much information as possible will help us to fill your
> > request promptly and correctly.</p>
> >
> >
> > <FORM ACTION="/cgi-bin/scsl/scln/infoill.pl" METHOD=POST>
> >
> > <INPUT TYPE=HIDDEN NAME="SEQUENCE" value="1">
> > <INPUT TYPE=HIDDEN NAME="LTYPE" value="P">
> >
> > <TABLE COLS=2 WIDTH="100%" BORDER=0>
> >
> > <TR>
> > <TD WIDTH="20%"><B>Name of Library:</B></td>
> > <TD WIDTH="75%"><INPUT TYPE=TEXT NAME="NAME" SIZE=60></TD>
> > </TR>
> >
> > <TR>
> > ***** <TD WIDTH="20%" VALIGN=TOP><B>Information
> > requested:</B></td><TD><TEXTAREA
> > NAME="NOTE1" WRAP="physical" ROWS=10 COLS=60></TEXTAREA></TD>
> > </TR>
> >
> > <TR>
> > <TD WIDTH="20%" VALIGN=TOP><B>Purpose for which
> > requested:</B></td><TD><TEXTAREA
> > NAME="NOTE2" WRAP="physical" ROWS=5 COLS=60></TEXTAREA></TD>
> > </TR>
> >
> >
> > <TR>
> > <TD WIDTH="20%"><B>Patron category:</B></td>
> > <TD valign=bottom>
> > <INPUT TYPE=RADIO NAME="PATRON" VALUE="Adult" CHECKED> Adult
> > <INPUT TYPE=RADIO NAME="PATRON" VALUE="Student"> Student
> > <INPUT TYPE=RADIO NAME="PATRON" VALUE="Technical"> Technical</TD>
> > </TR>
> >
> > <TR>
> > <TD WIDTH="20%" VALIGN=TOP><B>Sources checked:</B></td><TD><TEXTAREA
> > NAME="NOTE3" WRAP="physical" ROWS=5 COLS=60></TEXTAREA></TD>
> > </TR>
> >
> > <TR>
> > <TD WIDTH="20%" VALIGN=TOP><B>Notes:</B></td><TD><TEXTAREA
> > NAME="NOTE" WRAP="physical" ROWS=5 COLS=60></TEXTAREA></TD>
> > </TR>
> >
> >
> > </TABLE>
> >
> > <br><br>
> > <center><INPUT TYPE=SUBMIT style="font-weight: bold; font-size: 14pt"
> > VALUE="Next">&nbsp;&nbsp;&nbsp;<INPUT
> > TYPE=RESET style="font-size: 9pt" VALUE="Clear text"></center>
> > </FORM>
> >
> > </BODY>
> > </HTML>
> > --
> > Catherine Buck Morgan
> > Automation Librarian
> > South Carolina State Library
> > EMAIL: catherine at leo.scsl.state.sc.us
> > Phone: 803.734.8666 Fax 803.734.8676
> > Home page: http://www.state.sc.us/scsl/
> > Web catalog: http://www.state.sc.us/scsl/scslweb/welcome.html
> >
> > The opinions stated herein are not necessarily those of SCSL.
> >

-- 
Catherine Buck Morgan
Automation Librarian
South Carolina State Library
EMAIL: catherine at leo.scsl.state.sc.us
Phone: 803.734.8666 Fax 803.734.8676
Home page: http://www.state.sc.us/scsl/
Web catalog: http://www.state.sc.us/scsl/scslweb/welcome.html

The opinions stated herein are not necessarily those of SCSL.
-------------- next part --------------
#!/usr/bin/perl
#
#  CGI SCRIPT WHICH READS DATA PASSED FROM A WEB SERVER USING
#  THE   POST   METHOD
#
#  /inet/httpd/docs/cgi-bin/scsl/scln/infoill.pl
#
#
#
#  AUTHOR:    Bill Schmidt
#
#  DATE:      July 1999
#
#  PURPOSE:    
#
#    Takes the data entered by a user into an HTML Form and emails
#    it to the email address specified in the $em_addr variable.    The
#    server passes the data to this script using the   POST   method.
#


#  AUTHOR INPUT:   The author must assign the  Form Name  and e-mail 
#                                    address to the 2 variables immediately below.

$frm_nam = "SC Library Network ILL Information Request Form";
#  $em_addr = "catherine\@leo.scsl.state.sc.us";
#  $em_addr = "wschmid\@oir.state.sc.us";
$em_addr = "ill\@leo.scsl.state.sc.us";


#  $frm_nam     This is the   NAME   of the Form.  
#                           It's sole use is by the recipient to identify the specific Form
#                           from which the data came;  the name is specified by the Form's
#                           author - it is  NOT  user input !!!    The author can give the
#                           form an arbitrary name of arbitrary length made up of 
#                           alpha-numerics, underscores, dashes and spaces.   
#                           (Please stay away from "special" characters such as single or double
#                            quotes, colons, semicolons, etc. !!!)
#
#
#  $em_addr       This is the email address to which the user input is to be sent.

# END AUTHOR INPUT (Part 1)






#  Get the User Input From the Web Server and Place It in an 
#  Associative Array 

&get_post(*Data);


#  Set up link for final page (Accept and Cancel pages)

#     Default link is to Public Libraries

$ilink='<img src="/redball.gif" border=0> &nbsp;
<a href="http://www.state.sc.us/scsl/scln/ill/req.html">Submit Another ILL
Request</a>';

#    Change link if  Other Libraries'
if ($Data{'LTYPE'} eq "O") {

$ilink='<img src="/redball.gif" border=0> &nbsp;
<a href="http://www.state.sc.us/scsl/scln/ill/req2.html">Submit Another ILL
Request</a>';
}

#  End setting up link for final page



#  Output Information for verification by user

# Submitted data  (SEQUENCE = 1) is passed back to user 
#  for verification
if ($Data{'SEQUENCE'} eq "1") {


print <<EOF;
Content-type: text/html


<html>
<head>
<title>SC Library Network - ILL Information Request</title>
</head>

<body bgcolor="white">

<p><br>
<center>

<table border=0>

<!--
<tr>
<td align=left valign=top nowrap><b>Form Sequence</b></td> <td width="20"> &nbsp; </td>
<td align=left><b>$Data{'SEQUENCE'}</b></td>
</tr>

<tr>
<td align=left valign=top nowrap><b>Requested Action</b></td> <td width="20"> &nbsp; </td>
<td align=left><b>$Data{'ACTN'}</b></td>
</tr>
-->

<tr>
<td align=left valign=top nowrap><b>Name of Library</b></td> <td width="20"> &nbsp; </td>
<td align=left><b>$Data{'NAME'}</b></td>
</tr>

<tr>
<td align=left valign=top nowrap><b>Information Requested</b></td> <td width="20"> &nbsp; </td>
<td align=left><b>$Data{'NOTE1'}</b></td>
</tr>

<tr>
<td align=left valign=top nowrap><b>Purpose for which Requested</b></td> <td width="20"> &nbsp; </td>
<td align=left><b>$Data{'NOTE2'}</b></td>
</tr>

<tr>
<td align=left valign=top nowrap><b>Patron Category</b></td> <td width="5"> &nbsp; </td>
<td align=left><b>$Data{'PATRON'}</b></td>
</tr>

<tr>
<td align=left valign=top nowrap><b>Sources Checked</b></td> <td width="20"> &nbsp; </td>
<td align=left><b>$Data{'NOTE3'}</b></td>
</tr>

<tr>
<td align=left valign=top nowrap><b>Notes</b></td> <td width="20"> &nbsp; </td>
<td align=left><b>$Data{'NOTE'}</b></td>
</tr>


</table>
</center>

<p><br>


<FORM ACTION="http://www.state.sc.us/cgi-bin/scsl/scln/infoill.pl" METHOD=POST>

<center>
<table border=1>
<tr>
<td>
<table border=0>
<TR>

<TD valign=center><B><font color=blue>Accept:</font></B></td><td><INPUT
TYPE=RADIO NAME="ACTN"
VALUE="Accept" CHECKED></td>
</tr>
<tr>
<TD><B><font color=blue>Make Changes:</font> &nbsp; </B></td><td><INPUT
TYPE=RADIO NAME="ACTN"
VALUE="Change"></td>
</tr>

<tr>
<TD><B><font color=blue>Cancel Request:</font></B></td><td><INPUT TYPE=RADIO
NAME="ACTN"
VALUE="Cancel"></td>
</tr>

</TR>
</table>
</td>
</tr>
</table>

<INPUT TYPE=HIDDEN NAME="SEQUENCE" value="2">
<INPUT TYPE=HIDDEN NAME="LTYPE" value="$Data{'LTYPE'}">
<INPUT TYPE=HIDDEN NAME="NAME" value="$Data{'NAME'}">
<INPUT TYPE=HIDDEN NAME="NOTE1" value="$Data{'NOTE1'}">
<INPUT TYPE=HIDDEN NAME="NOTE2" value="$Data{'NOTE2'}">
<INPUT TYPE=HIDDEN NAME="PATRON" value="$Data{'PATRON'}">
<INPUT TYPE=HIDDEN NAME="NOTE3" value="$Data{'NOTE3'}">
<INPUT TYPE=HIDDEN NAME="NOTE1" value="$Data{'NOTE1'}">
<INPUT TYPE=HIDDEN NAME="NOTE"  value="$Data{'NOTE'}">

<p>
<INPUT TYPE=SUBMIT  style="font-weight: bold; font-size: 14pt" VALUE="Submit">
</center>
</FORM>

<p><br>
</body>
</html>
EOF

exit(0);

#  End output of data for verification by the user


#  Data has been Accepted, Data needs to be changed, or the
# transaction has been cancelled
} elsif ($Data{'SEQUENCE'} eq "2") {


# Data has been accepted, so email it
     if ($Data{'ACTN'} eq "Accept") {




open(MAIL, "|mail $em_addr");


# AUTHOR INPUT (Part 2):   User must tailor the   PRINT   statements
#                                                to reflect all of the Form's variables !!!!


print MAIL "Form Name:\t\t$frm_nam\n\n";

print MAIL "Library Name:\t\t$Data{'NAME'}\n\n\n";
print MAIL "Information Requested:\n$Data{'NOTE1'}\n\n\n";
print MAIL "Purpose for which Requested:\n$Data{'NOTE2'}\n\n\n";
print MAIL "Patron Category:\t$Data{'PATRON'}\n\n\n";
print MAIL "Sources Checked:\n$Data{'NOTE3'}\n\n\n";
print MAIL "Notes:                            \n$Data{'NOTE'}\n";

# END AUTHOR INPUT   (Part 2)


close(MAIL);

print <<EOF;
Content-type: text/html


<html>
<head>
<title>SC Library Network - ILL Information Request</title>
</head>

<body bgcolor="white">
<p><br>
<center>
<h2>Your Request Has Been Forwarded to the SC State Library</h2><p>
<h3>Thank You !</h3>
<p><br>

<table border=0>
<tr>
<td>
<img src="/redball.gif" border=0> &nbsp;
<b><a href="http://www.state.sc.us/scsl">SC State Library Home Page</a><p>

$ilink

</b>
</td>
</tr>
</table>

</center>

<p><br>
</body>
</html>
EOF

exit(0);

#  End Data accepted


#  Data needs to be changed, so redisplay it in the HTML Form
#  in which it was originally entered

    } elsif ($Data{'ACTN'} eq "Change") {



# BEGIN - Assign Patron Category as Adult/Student/Technical

$ALTL='<TR>
<TD WIDTH="20%"><B>Patron category:</B></td>
<TD valign=bottom>
<INPUT TYPE=RADIO NAME="PATRON" VALUE="Adult" CHECKED> Adult  
<INPUT TYPE=RADIO NAME="PATRON" VALUE="Student"> Student 
<INPUT TYPE=RADIO NAME="PATRON" VALUE="Technical"> Technical</TD>
</TR>';

if ($Data{'PATRON'} eq "Student") {
$ALTL='<TR>
<TD WIDTH="20%"><B>Patron category:</B></td>
<TD valign=bottom>
<INPUT TYPE=RADIO NAME="PATRON" VALUE="Adult"> Adult  
<INPUT TYPE=RADIO NAME="PATRON" VALUE="Student" CHECKED> Student 
<INPUT TYPE=RADIO NAME="PATRON" VALUE="Technical"> Technical</TD>
</TR>';
} elsif  ($Data{'PATRON'} eq "Technical") {
$ALTL='<TR>
<TD WIDTH="20%"><B>Patron category:</B></td>
<TD valign=bottom>
<INPUT TYPE=RADIO NAME="PATRON" VALUE="Adult"> Adult  
<INPUT TYPE=RADIO NAME="PATRON" VALUE="Student"> Student 
<INPUT TYPE=RADIO NAME="PATRON" VALUE="Technical" CHECKED> Technical</TD>
</TR>';
}
# END - Assigning Request-4-Week-Renewal





print <<EOF;
Content-type: text/html


<html>
<head>
<title>SCLN Inter-Library Loan Service - Information Request Form</title>
</head>
<body>
<table>
<tr><td width=120><img align=left src="/scsl/scln/ill/blue6.gif"></td><td 
width=420><center><h2>South
Carolina Library Network<br>Inter-Library Loan Service<br>Information Request
Form</h2></center></td></tr></table>
<hr>

<p>Use this form to request information from the State Library on subjects of interest to your patrons.  Be as detailed as possible in describing the information requested, and how it will be used (e.g. for personal interest, term paper, etc.).  Identifyi
ng the age level (adult or student) of the patron and sources previously checked will help us to supply appropriate materials.</p>

<p>Providing as much information as possible will help us to fill your request promptly and correctly.</p>


<FORM ACTION="http://www.state.sc.us/cgi-bin/scsl/scln/infoill.pl" METHOD=POST>

<INPUT TYPE=HIDDEN NAME="SEQUENCE" value="1">
<INPUT TYPE=HIDDEN NAME="LTYPE" value="$Data{'LTYPE'}">

<TABLE COLS=2 WIDTH="100%" BORDER=0>

<TR>
<TD WIDTH="20%"><B>Name of Library:</B></td>
<TD WIDTH="75%"><INPUT TYPE=TEXT NAME="NAME" value="$Data{'NAME'}" SIZE=60></TD>
</TR>

<TR>
<TD WIDTH="20%" VALIGN=TOP><B>Information requested:</B></td><TD><TEXTAREA
NAME="NOTE1" WRAP ROWS=10 COLS=60>$Data{'NOTE1'}</TEXTAREA></TD>
</TR>

<TR>
<TD WIDTH="20%" VALIGN=TOP><B>Purpose for which requested:</B></td><TD><TEXTAREA
NAME="NOTE2" WRAP ROWS=5 COLS=60>$Data{'NOTE2'}</TEXTAREA></TD>
</TR>


$ALTL

<TR>
<TD WIDTH="20%" VALIGN=TOP><B>Sources checked:</B></td><TD><TEXTAREA
NAME="NOTE3" WRAP ROWS=5 COLS=60>$Data{'NOTE3'}</TEXTAREA></TD>
</TR>

<TR>
<TD WIDTH="20%" VALIGN=TOP><B>Notes:</B></td><TD><TEXTAREA
NAME="NOTE" WRAP ROWS=5 COLS=60>$Data{'NOTE'}</TEXTAREA></TD>
</TR>

</TABLE>

<br><br>
<center><INPUT TYPE=SUBMIT style="font-weight: bold; font-size: 14pt"
VALUE="Next">
</center>

</FORM>


</BODY>
</HTML>
EOF

exit(0);

#  End redisplay of Data in the HTML Form
#  in which it was originally entered

}
 }


#  ILL request has been CANCELLED
print <<EOF;
Content-type: text/html


<html>
<head>
<title>SC Library Network - ILL Information Request</title>
</head>

<body bgcolor="white">
<p><br>
<center>
<h2>Your Request Has Been Has Been Cancelled</h2><p>
<!-- <h3>Thank You !</h3> -->
<p><br>

<table border=0>
<tr>
<td>
<img src="/redball.gif" border=0> &nbsp;
<b><a href="http://www.state.sc.us/scsl">SC State Library Home Page</a><p>

$ilink

</b>
</td>
</tr>
</table>

</center>

<p><br>
</body></html>
EOF
exit(0);


# END  -  Output the Final Part of the HTML Document



# *********************   END OF PROGRAM   ***********************





# **************************************************************************
# **************************************************************************
#
#         Below are the  SUBROUTINES  used by the code above
#
#  Unless a bug is discovered in the subroutines, they
#  should   NOT   be changed, although the user may wish to add additional 
#  subroutines to this section if this script is used as the basis for 
#  another script



# get_post ()
#
#  Gets the user input data passed by the Web server to this program
#  using the   POST   method, and builds the associative array.
#
#  Exit Conditions:
#
#  $key         -  Contains the parameter name assigned by the Form
#                  author to the input element (e.g., text box, radio
#                  button, etc.) which corresponds to this array record.
#                  (e.g., $key = abc, where <input name="abc" . . > )
#
#  $Data{$key}  -  Contains the value entered by the user into the
#                  input element corresponding to the parameter 
#                  name, $key
#


sub get_post {
  local(*Data) = @_;

  # Validate   POST   and TYPE
  if ($ENV{'REQUEST_METHOD'} ne "POST") {
     print "This should be a posted form and it isn't.\n";
     exit;
  }

  if ($ENV{'CONTENT_TYPE'} ne "application/x-www-form-urlencoded") {
     print "This script can only work on form results.\n";
     exit;
     }

  # Get the Data Passed by the Server
  &get_post_data(*Data, $ENV{'CONTENT_LENGTH'});
}




#
# get_post_data (*Data)
#
#  Gets the POSTed data and puts its key-value pairs into the 
#  associative array, Data.
#

sub get_post_data {
  local(*Data, $len) = @_;
  local(@lines, $rawdata);

  # Read the Data into a Single String
  read(STDIN, $rawdata, $len);

  # Split the Data on &
  foreach $entry (split(/&/, $rawdata)) {
    local($key, $data) = split(/=/,$entry, 2);
    # convert + to spaces in data
    $data =~ s/\+/ /g;
    &decode(*data);
    $Data{$key} = $data;
  }
}




# decode(*line)
#
#  All "dangerous" characters are sent by the browser in "escaped" form,
#  %<hex>. This routine converts these %<hex> fields back into their 
#  non-hexadecimal form which are usable by the program.
#  (e.g.,  %20  =  is the hexadeciaml representation of a space) 
#
#  For further information, see:
#
#    RFC 1630,  Universal Resource Identifiers in WWW
#      (http://ds.internic.net/rfc/rfc1630.txt)
#
#    RFC 1630,  Universal Resource Locators (URL)
#      (http://ds.internic.net/rfc/rfc1738.txt)
#
#    Hypertext Transfer Protocol - HTTP/1.0
#      (http://www.ics.uci.edu/pub/ietf/http/
#                                       draft-ietf-http-v10-spec-05.ps.gz)


sub decode {
  local(*line) = @_;
  local($pos) = $[;
  
  while (($pos = index($line, '%', $pos)) >= $[) {
    local($hexch) = pack('c', hex(substr($line, $pos + 1, 2)));
    substr($line, $pos, 3) = $hexch;
  }
} 



More information about the Web4lib mailing list