Saturday, November 2, 2024

Simple User Request Forms

We often have the need for simple forms that request certain actions like adding a new user, etc. A simple perl script lets us do this with a web form that then emails the results.

The example here can be modified to meet your needs. The things that you need to know are noted in comments.

#!/usr/bin/perl
use CGI qw(:standard);
$posting=param('posting');

if (defined $posting) {
# this section only happens when the form is submitted
  $email=param('ab_email');
# your email may not be /bin/mail 
  open MAIL, "|/bin/mail -s "IT User Request" itstaff@yourcompany.com";
  $requestor="|/bin/mail -s "Your IT User Request" $email";
  open MAILO, $requestor;
  print MAIL "Subject: IT user requestnn";
  print MAILO "$Subject: Your IT user requestnn";
  print MAILO "nConfirming your request:nn";
# print the results to mail
foreach $i (param) {
# skip the posting flag
  next if $i =~ /posting/;
  foreach $j (param($i) ) {
    $v=$i;
# strip off the prefix
    $v =~ s/^.._//;
    print MAIL "$v = $jn";
    print MAILO "$v = $jn";
  }
}
print header, <<EOF;
<html><head><title> IT User Request</title></head><body>
<h2>Accepted, thank you</h2>
<form action="/cgi-bin/simpleform.pl" method=POST>
EOF
foreach $i (param) {
  next if $i =~ /posting/;
  foreach $j (param($i) ) {
    $v=$i;
    $v =~ s/^.._//;
    print "<br>$v = $jn";
  }
}
print <<EOF;
<p><input type=submit name=accept value="OK">
</form>
</body></html>
EOF
exit 0;

}
# this is what happens when the script is first called
print  header, <<EOF;
<html><head><title> IT User Request</title></head><body>
<h2>IT User Request</h2>
<form action="/cgi-bin/simpleform.pl" method=POST>
#
# you can modify any of these.  The first 3 characters of 
# the variable names let us easily control order if we need to
#
<p>Requested by: <input type=text name=aa_requestor size=20>
<p>Your email: <input type=text name=ab_email size=20>
<p>Your telephone: <input type=text name=ab_phone size=20>
<p><input name=ac_type type=radio value="New User">New User
<input name=ac_type type=radio value="Terminate User">Terminated User
<p>User's Login <input type=text name=ad_user_login size=4>
<p>User's name: <input type=text name=ae_username size=20>
<p>(if new) Desired password: <input type=text name=af_desired_password size=20>
<p>Systems to add or terminate:
<p> <input name=ag_systems type=checkbox value="Network">Network
<p> <input name=ag_systems type=checkbox value="Unix">Unix
<p> <input name=ag_systems type=checkbox value="File and Print">File and Print
<p> <input name=ag_systems type=checkbox value="E-Mail">E-Mail
<p> <input name=ag_systems type=checkbox value="E-Fax">E-Fax
<p> <input name=ag_systems type=checkbox value="Telephone/Voice Mail">Telephone/Voice Mail
<p><textarea name=zz_notes rows=10 cols=80 wrap=physical></textarea>
#
<p><input type=submit name=posting>
</form>
</body></html>
EOF

Download simpleform.pl (right click and use “save target as”)
More Code

Please Read the Disclaimer
Copyright and Reprint Info

A.P. Lawrence provides SCO Unix and Linux consulting services http://www.pcunix.com

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

Streamline your workflow with our leading software solutions & ai integrations.