
novice1
Novice
Jun 30, 2002, 3:10 AM
Post #6 of 28
(3824 views)
|
|
Re: [novice1] basic submit to text file script
[In reply to]
|
Can't Post
|
|
Dave - someone had recommended this script the other day from another newsgroup.. I couldn't get it going, of course that # missing on the first line... Anyway, now that it is working - it does append each submission to the previous in the text file, but doesn't have the time... I can't get it to view/display the results either. And what can I use for the $link since no hostname is avaiable. I was thinking just a reference to the location of the actual html file on the server.. I don't know, but these guys I assume are atheists? Hey anyway, so these atheists start off with okay comments, but towards the end of the file there are none... --- #! /usr/local/bin/perl ################################################################## # TC-Form.cgi is a modification of quickform.cgi written by Leif M. Wright. # Quickform.cgi originally does not send an email but I needed a small script that did # notify me whenever new data was added to a file. I added a simple e-mail procedure to # make this happen. # # Most credit still goes to Leif M. Wright.... # # Jaco Benard # TECH-Concepts # jbenard@tech-concepts.com # ################################################################## # # this tells the program where to place a link for the user # once they are done. $link ="http://www.conservatives.net/atheist/"; # this is where the info will be written to - you need to specify a real directory $file ="/usr/home/leif/public_html/conservatives/atheist/scripts/results.txt"; #must be read/writable # ################################################################## if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $contents{$name} = $value; } } chop($date = `date`); # Now with the program ########################################################### # Has to output a Content-type print "Content-type: text/html\n\n "; # Check to see if all required information was entered # If you want a field to be required, add it here. &no_cigar unless $contents{'name'}; &no_cigar unless $contents{'street'}; &no_cigar unless $contents{'city'}; &no_cigar unless $contents{'state'}; &no_cigar unless $contents{'zip'}; &no_cigar unless $contents{'country'}; sub no_cigar { print <<"HTML"; <HTML><HEAD><TITLE>Form Incomplete</TITLE></HEAD> <BODY> <H1>Form Incomplete</H1> I'm sorry, the form was not filled completely.<br> Please Return to the form and fill it out completely.<p> Thank you. <HR> <a href=\"$contents{'url'}\">Return to the $contents{'formname'} page</a> </BODY></HTML> HTML exit; } # They go here if the form was submitted # successfully. Now this page will send them # off to where ever specify in the "link" field above. print <<"HTML"; <HTML><HEAD><TITLE>Entry successful</TITLE></HEAD> <BODY> <H1>Entry successful!</H1> <p> <hr noshade> <p> <H2>$contents{'name'}, I have received your form!</H2> Your information will be processed immediately, <b>$contents{'name'}</b>. Thank you. <p> <HR noshade> <A HREF=\"$link\">Back to the home page</A>. <a href="results.txt">View this form's results</a>. </BODY> </HTML> HTML #print "Content-type: text/plain\n\n "; open(OUTPUT, ">>$file"); print OUTPUT "_______________________________\n"; print OUTPUT "Date: $date\n"; print OUTPUT "FORM NAME: $contents{'formname'}\n"; print OUTPUT "NAME: $contents{'name'}\n"; print OUTPUT "EMAIL: $contents{'email'}\n"; print OUTPUT "STREET: $contents{'street'}\n"; print OUTPUT "CITY: $contents{'city'}\n"; print OUTPUT "STATE: $contents{'state'}\n"; print OUTPUT "POSTAL CODE: $contents{'zip'}\n"; print OUTPUT "COUNTRY: $contents{'country'}\n"; print OUTPUT "PHONE: $contents{'phone'}\n"; print OUTPUT "COMMENTS: $contents{'comments'}\n"; close (OUTPUT); open (MAIL, "| /usr/lib/sendmail -oi -n -t" ); print MAIL <<MAIL_MESSAGE; To:you\@yourdomain.com From:yourform\@yourdomain.com You just received a new order... MAIL_MESSAGE close MAIL; exit;
|