CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Assist on a form

 



CJ2005
New User

Mar 24, 2010, 10:46 AM

Post #1 of 4 (655 views)
Assist on a form Can't Post

I have a form to submit some information and it is working fine. I need to add the ability to send an attachment from the form anyone have advice. Here is the code that is sending the form data:
#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
# This script is designed to work with the approval form that will get posted on the field
# analysts sharepoint page.
print header;
print start_html("Results");

# Set the PATH environment variable to the same path
$ENV{PATH} = "/usr/lib";

# open the pipe to sendmail
open (MAIL, "|/usr/lib/sendmail -t") or
&dienice("Can't fork for sendmail: $!\n");

# Email recipient list separate with a comma. Should be members of the best practices team so it can be brought
# up in future meetings for discussion
my $recipient = 'email@home.com';

# Start printing the mail headers
# The recipient/recipients list is above
print MAIL "To: $recipient\n";

# Who the email will show up from
print MAIL "From: Sharepoint\n";

# print a subject line and the first line in the email
print MAIL "Subject: Script Approval Request\n\n";
print MAIL "Script Approval Request Form\n\n";

# Now print the body of your mail message.
# This section pulls the variables sent from the web form
# it will pull each and print them to the email with the label
foreach my $p (param()) {
print MAIL "$p = ", param($p), "\n\n";
}

# Closes the email to send it
close(MAIL);

# Now print a thank-you page
print <<EndHTML;
<h2>Thank You</h2>
<p>Thank you for your submission .</p>

EndHTML

print end_html;

# Just in case there is an error somewhere
sub dienice {
my($errmsg) = @_;
print "<h2>Error</h2>\n";
print "<p>$errmsg</p>\n";
print end_html;
exit;
}

The form looks like this:
<html>
<h1><center>Script Approval Form</center></h1>




<form name="Approval Request" method="post" action="http://put.com/cgi-bin/approval.cgi"

enctype="multipart/form-data">
<table>
<tr>
<td valign="top"">
<label for="site">Site</label>
</td>
<td valign="top">
<input type="text" name="Site" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="name">Requestor</label>
</td>
<td valign="top">
<input type="text" name="Requester" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="Script">Script Name with full Path:</label>
</td>
<td valign="top">
<input type="text" name="Script" maxlength="100" size="60">
</td>
</tr>
<tr>
<td valign="top">
<label for="purpose">Purpose of Script:</label>
</td>
<td valign="top">
<input type="text" name="Purpose" maxlength="100" size="90">
</td>
</tr>
<tr>
<td valign="top">
Service type:
</td>
<td valign="top">
Electric - <input type="checkbox" name="Meter Type" value="Electric "/>
Gas - <input type="checkbox" name="Meter Type" value="Gas "/>
Water - <input type="checkbox" name="Meter Type" value="Water "/>
</td>
</tr>
<tr>
<td valign="top">
Network Type:
</td>
<td valign="top">
1-Way - <input type="checkbox" name="Network Type" value="1-way "/>
2-Way - <input type="checkbox" name="Network Type" value="2-way "/>
</td>
</tr>
<tr>
<td valign="top">
Use (will this script submit anything external to Landis+Gyr):
</td>
<td valign="top">
Internal - <input type="checkbox" name="Use" value="Internal"/>
External - <input type="checkbox" name="Use" value="External"/>
</td>
<tr>
<td valign="top">
If external, list utility name:
</td>
<td valign="top">
<input type="text" name="Utility Email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="approval1">SME/Site Testing:</label>
</td>
<td valign="top">
<input type="text" name="SME Approver" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="appdate1">Date Approved</label>
</td>
<td valign="top">
<input type="text" name="SME Date Approved" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="approval2">Site Manager</label>
</td>
<td valign="top">
<input type="text" name="Program Manager" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="approvadate2">Date Approved</label>
</td>
<td valign="top">
<input type="text" name="Date Approved" maxlength="80" size="30">
</td>
</tr>
</table>
<p><input type="submit" value="Submit">
</form>
</html>

If I add this line the attachment gets added to the form but not sent as an attachment:
<p>Attachment: <INPUT TYPE="file" NAME="attachedfile" MAXLENGTH=50 ALLOW="text/*" >

Thanks


(This post was edited by CJ2005 on Mar 24, 2010, 10:48 AM)


7stud
Enthusiast

Mar 25, 2010, 3:20 AM

Post #2 of 4 (634 views)
Re: [CJ2005] Assist on a form [In reply to] Can't Post

 Search google for 'code tags'. Read the first ten results, then come back and post what you've learned.


CJ2005
New User

Mar 25, 2010, 5:50 AM

Post #3 of 4 (629 views)
Re: [7stud] Assist on a form [In reply to] Can't Post

I have seen this same post from you on a few topics. I saw a lot about HTML tags and use of the <code> tag. I also saw some PHP things. What did not pop up was how to get the perl script to attach a document.

Thanks for the response


FishMonger
Veteran / Moderator

Mar 25, 2010, 6:00 AM

Post #4 of 4 (627 views)
Re: [CJ2005] Assist on a form [In reply to] Can't Post

Apparently you didn't understand what 7stud was trying to convey.

ALWAYS use the code tags when posting your code. Failure to do so will limit the amount of help you receive because it's difficult to follow unformatted code.


Have you read the documentation for the CGI module that you're using?

http://search.cpan.org/~lds/CGI.pm-3.49/lib/CGI.pm#PROCESSING_A_FILE_UPLOAD_FIELD

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives