APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

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 request\n\n";
  print MAILO "$Subject: Your IT user request\n\n";
  print MAILO "\nConfirming your request:\n\n";
# 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 = $j\n";
    print MAILO "$v = $j\n";
  }
}
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 = $j\n";
  }
}
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






Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Simple User Request Forms




Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence



Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





Computers are like Old Testament gods; lots of rules and no mercy. (Joseph Campbell)

Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. (Arthur Conan Doyle)












This post tagged: