Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

process form WITHOUT output?

Status
Not open for further replies.

0ddba11

Technical User
Feb 11, 2001
3
US
...this qualifies as a question from an
idiot, perhaps. i want to hack a formmail-type
script to process a form and print(MAIL
*WITHOUT* subsequently writing to a "response"
html page or "redirecting." my hacks all fail
when they don't include a print to file0
or redirect. obvoiusly, i'm missing something
elementary in the way perl interacts with
forms. enlighten me, somebody.
 
Please show the part of your script that's failing. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
thanks... here's the whole thing...comment shows where it fails. when i write to an output file (http) instead of exiting, it works,

++++++++++++++++++++

#!/usr/local/bin/perl -w

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
#read input
@pairs = split(/&/, $buffer);
#split input up
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
#input separated

$mailprog = 'bin/sendmail';
#specify mail address

$recipient = 'adam@hermes-grp.com';
#specify email address

$subject = 'Form Submission';
#specify subject
$redirect = '#specify URL to go to once mail has been sent

@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');
#create array with months and days for later use in mail

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($hour < 10)
{ $hour = &quot;0$hour&quot;; }
if ($min < 10)
{ $min = &quot;0$min&quot;; }
if ($sec < 10)
{ $sec = &quot;0$sec&quot;; }
$date = &quot;$days[$wday], $months[$mon] $mday, 19$year at $hour\:$min\:$sec&quot;;
#specify time and date

open (MAIL, &quot;|$mailprog -t&quot;) or &amp;dienice(&quot;Can't access $mailprog!\n&quot;);
#start email
print MAIL &quot;To: $recipient\n&quot;;
#print recipient
print MAIL &quot;Reply-to: $FORM{'email'} ($FORM{'name'})\n&quot;;
#print reply to information
print MAIL &quot;Subject: $subject\n\n&quot;;
#print subject
print MAIL &quot;\n&quot;;
#print blank line
print MAIL &quot; The following form was sent by: $FORM{'name'}\n&quot;;
#print sent from
print MAIL &quot; on $date\n\n&quot;;
#print date
print MAIL &quot;\n\n&quot;;
#print 2 blank lines

foreach $key (keys(%FORM)) {
print MAIL &quot;$key : $FORM{$key}\n\n&quot;;
}

#fails below, sends mail but yields server config error
close(MAIL);
exit;
#close(send) email

#error handle code:
sub dienice {
($errmsg) = @_;
print &quot;<center><h2>There was an ERROR sending this form</h2></center>\n&quot;;
print &quot;$errmsg<p>\n&quot;;
print &quot;</body></html>\n&quot;;
exit;
}
 
Oh, i get it, you just want it to perform the function and not return anything to the browser. I have been taught to always return something, or in the least, to redirect to the original page's location.
i don't know if doing so is absolutely necessary, but i don't know of any ways around it. i'll look and ask around here and report if i do find something.
oh wait, you could just have javascript on the original page to execute the cgi script as it's function, but not reload the whole page (maybe). i don't know enough javascript off-hand. like i said, i'll ask, see if anyone knows (as i'd like to know myself). &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
...can i do this by opening STDOUT to dev/null?

if so, how?

any help will be appreciated...
 
No, it's that the browser or webserver (i don't know which, probly the webserver, though) is expecting a return, it doesn't have anything to do with the perl.
Also, noone i knew had an answer better than what i wrote. Maybe someone else here does, but they have yet to post... &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top