October 2002
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
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. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar