Click to See Complete Forum and Search --> : Parsing submitted info into a listing.


VRay
02-23-2001, 08:13 PM
Here is the setup: Multiple clients will be submitting an order from a web page each day, the info submitted will be their name, their location (building and cubicle number) and the item number on the menu that they want for lunch. Also any special requests they may have, like no mushrooms on the salad, for example. I need to recieve all this data and compile it into a list which I send on to the folks who cook and deliver the food. I will also need totals of each menu item ordered. What would be the best way to do this? My initial thought was for a webform to be submitted which I recieve via email and then run some sort of program to extract the relevent info and write it to a list. Or maybe a database type program would be better? I don't need to hang on to any of the data, once I submit the final list, my job is done. Any suggestions or pointers would be appreciated. I have a pII-300 box running RH7 at home which I would like to use for the task. I am not much of a programmer so I am hoping I can find some pre-written script or program that can do this sort of thing.

Thanks in advance...

Fandelem
02-24-2001, 02:48 AM
i have very limited time, but this will definitely help you.

i am going to show you two files - the .html file is basically where they go to submit the data, and the .pl file is what processes it and writes it into a file. this should help you out tremendously. then i recommend checking out FormMail.pl (do a search for it, you're bound to come up with the link to downloading it) and look at the mailing subroutine and cut and paste and modify to your liking. (the .html portion can be found at www.fandelem.com/poetry/submit.html (http://www.fandelem.com/poetry/submit.html) however while it does submit, i haven't fixed my viewing portion of it yet.. midterms and such happened this week ..lol)

*note: you can have your html in your .pl file, but this was done before i knew you could, and i never have gotten around to changing it.

submit.html

<HTML>
<HEAD>
<script>
<!-- // Hide from JavaScript impaired browsers
function check() {
if (document.submit.email.value == "") {
alert("You forgot to enter an email!")
return 1;
}

else if (document.submit.poem.value == "") {
alert("You forgot to enter your poem!")
return 1;
}
else if (document.submit.title.value == "") {
alert("You forgot to enter your title!")
return 1;
}
else {
document.submit.save.value = "been saved. (click on send now)"
}

}

BrowserName = navigator.appName;

function browserBack() {
if (BrowserName == "Netscape") {
parent.off.history.back();
}
else { // IE
history.back();
}
return;
}
// End hiding -->
</script>

<TITLE></TITLE>
<center><input type=button width=97 onclick="browserBack()" value="back one page"></center>
</HEAD>

<BODY BGCOLOR=#FFFFFF>
<style type="text/css">
<!--a:hover{color:#ffffff}
a{text-decoration:none}
.body{
font-family: verdana;
font-size: 8pt}-->
</style>

<STYLE> a {text-decoration:none} </STYLE>

<body bgcolor=000000 text=ffffff link=769257 vlink=769257 alink=769257>

<table border=0 cellpadding=0 cellspacing=0 width=100% height=100%>
<tr>
<td align=middle valign=middle>

<table border=0 cellpadding=2 cellspacing=0><tr><td bgcolor=000000>
<table border=1 bordercolor=769257 cellpadding=8 cellspacing=0>
<tr>
<td bgcolor=000000>
<font face=verdana size=1>

<center>

<div align=center>
<font size=+.5>
<FORM name=submit ACTION="http://www.fandelem.com/cgi-bin/submitpoem.pl" METHOD="POST">

Please enter your Email:<br> <INPUT name="email" size=25> <BR>
Title of Poem:<br> <INPUT name="title"size=55><br>
Your Poem: <br><TEXTAREA COLS=45 ROWS=20 name="poem"></TEXTAREA><BR>
<br>Your poem has <input type=text value="not been saved yet!!" size=30
name="save"><br>
<br><input type=button value="Save Your Work" onClick=check()>


<br><br><input TYPE="submit" value="To Send Push Here!"><input TYPE="reset" value="Reset Me!">
</form>

</BODY>
</HTML>


and now the .pl script

#!/usr/local/bin/perl -w
#####################
# #
use CGI; #
my $cgi = new CGI; #
# #
#####################


my $file = "/home/kdavis/www/poetry/submissions.html";
my $email = $cgi->param('email');
my $title = $cgi->param('title');
my $poem = $cgi->param('poem');


# this is the only way i know how to do $date hehe stole it from formail.pl
my (
$sec,
$min,
$hour,
$mday,
$mon,
$year,
$wday,
$date,
$time,
@days,
@months,
);

# Define arrays for the day of the week and month of the year. #
@days = ('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June' ,'July',
'August','September','October','November','Decembe r');

# Get the current time and format the hour, minutes and seconds. Add #
# 1900 to the year to get the full 4 digit year. #
($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$year += 1900;

# Format the date. #
$date = "$days[$wday], $months[$mon] $mday, $year at $time";

# print html stuff
header();
# sort everything submitted.
check();
# let's store everything in a file.
logpoem();
# print footer
footer();

##################################################
#
# SUB ROUTINES
#
##################################################
sub check {
my (
$buffer,
$email,
$title,
$poem,
$pair,
@pairs,
);

if ($ENV{'REQUEST_METHOD'} eq 'POST') {
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);
}

# For each name-value pair: #
foreach $pair (@pairs) {

# Split the pair up into individual variables. #
($email, $title, $poem) = split(/=/, $pair);

# Decode the form encoding on the name and value variables. #
# $email =~ tr/+/ /;
# $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
#
# $value =~ tr/+/ /;
# $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

# If they try to include server side includes, erase them, so they
# aren't a security risk if the html gets returned. Another
# security hole plugged up.
# $value =~ s/<!--(.|\n)*-->//g;
}
}
sub header {
print <<"(Dynamic Created Document)";
Content-type: text/html


<HTML>
<HEAD>
<meta HTTP-EQUIV=\"refresh\" CONTENT=\"2; URL=http://www.fandelem.com/poetry/otherpoets.html\">
<script language=\"JavaScript1.1\">
<!-- // Hide from JavaScript impaired browsers

BrowserName = navigator.appName;

function browserBack() {
if (BrowserName == \"Netscape\") {
parent.off.history.back();
}
else { // IE
history.back();
}
return;
}
// End hiding -->
</script>

</HEAD>


<p>

<style type=\"text/css\">
<!--a:hover{color:#ffffff}
a{text-decoration:none}
.body{
font-family: verdana;
font-size: 8pt}-->
</style>

<STYLE> a {text-decoration:none} </STYLE>

<body bgcolor=000000 text=ffffff link=769257 vlink=769257 alink=769257>

<table border=0 cellpadding=0 cellspacing=0 width=100% height=100%>
<tr>
<td align=middle valign=middle>

<table border=0 cellpadding=2 cellspacing=0><tr><td bgcolor=000000>
<table border=1 bordercolor=769257 cellpadding=8 cellspacing=0>
<tr>
<td bgcolor=000000>
<font face=verdana size=1>

<center>
<p>
<div align=left>
<font size=+.5>
<p><br><br><h2>Redirecting to the main page.. </h2><p><br><br><br>If this doesn't work, click
<A HREF=\"http://www.fandelem.com/poetry/otherpoets.html\">here</a>.</BODY>

(Dynamic Created Document)

}


# this prints the footer information (last modified information)
sub footer {
print <<"(footer)";
<hr><SCRIPT TYPE=\"text/javascript\" LANGUAGE=\"JavaScript\">
<!--//hide script from old browsers
document.write( \"<br>Generated at \"+ document.lastModified );
//end hiding contents -->
</SCRIPT>
</div></tr></td></table></table></table>

</BODY>
</HTML>


(footer)
}

# (this was ripped from one of matt's scripts and i altered it around)
# this will grab the IP address, poem title, and month selected and log it into a file.
# make sure the file is chmod 777
sub logpoem {
my (
$buffer,
$name,
$value,
$pair,
%FORM,
@pairs,
$temptitle,
);

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

# Stop people from using subshells to execute commands
# Not a big deal when using sendmail, but very important
# when using UCB mail (aka mailx).
$value =~ s/~!/ ~!/g;

# Uncomment for debugging purpose
# print "Setting $name to $value<P>";
$FORM{$name} = $value;
}

# non-destruct read/write mode.
open (INFILE, ">> $file") or die;

# bring back up to the beginning of file now.
seek (INFILE, 0, 0) or die;

# now we'll print the info submitted.
print INFILE "<A NAME=\"$title\"></a>\n<h3>title: $title</h3>\n";
print INFILE "\n<p>\n<pre>\n$poem\n</pre>\n";
print INFILE "<p><font size=-1><a href=\"mailto:$email\">$email</a> ";
print INFILE "posted on $date from $ENV{'REMOTE_ADDR'}.</font>\n";
print INFILE "<hr>\n";
close INFILE or die;

}
#
#
################################################## ###


i apologize for not intending anything- but it's almost 2am and i'm very, very drunk. but i figured this would help you out. if you have any specific questions i'll answer them by this weekend (if no one else already has) - a lot of people have spent hours helping me (via thisboard) and i'm more than willing to return the favor! ;o)

my best-

~kyle

edit: hint- if you are having troubles with this not line wrapping when you cut and paste, try cut and pasting it in windows in microsoft word - it will linewrap all pretty then you can cut and paste from there to where ever (just another tidbit of info.. sometimes code blocks don't cut pretty i've noticed.)

and now i will sleep away my drunkeness ;o)

[ 24 February 2001: Message edited by: Fandelem ]

[ 24 February 2001: Message edited by: Fandelem ]

VRay
02-24-2001, 03:36 AM
Haha, I am laffing my *** off! I hope you don't have too much of a bad headachein the morn. I just got in and am also little too f-ed up to properly absorb all of this, I shall tackle it in the morning. Thanks a million for the time you took to help me out. please check back as I am sure i will have a question or two...

VRay
02-24-2001, 02:56 PM
Ok, I have looked at it all a little closer... I am familiar with formmail.pl, I have used it and will be glad to use it for this application. But i am not sure if I understand how the the pl script will work, but then I am unfamiliar with email using linux. So, say I recieve 100 emails, what email proggie should I use, or do I need to set up my comp as a mail server? In some ways i would prefer to use a web based email program so i can do this task from anywhere (I'd never see my girlfriend :( if I have to do it from home each day)Do I then run the script to gather all the data? I think I am a little over my head here....

[ 24 February 2001: Message edited by: VRay ]

[ 24 February 2001: Message edited by: VRay ]

Fandelem
02-24-2001, 04:59 PM
here is my submail routine i just wrote:


sub send_mail {

############
#
# $recipient, $email and $title are defined in submitform()
# or they should be set as (example)
# <INPUT type=hidden name="recipient" value="fandelem@hotmail.com">
# so change them as necessary.
#
############

# mail admin

open(MAIL,"|$mailprog -t") or bail("cannot close $MAIL: $!");

print MAIL "To: $recipient\n";
print MAIL "From: $email\n";

if ($title) { print MAIL "Subject: (title)$title\n\n" }
else { print MAIL "Subject: Poetry Submission\n\n" }

print MAIL "Below is the result of your form submitted by $email.\n";
print MAIL "It was submitted on $datee\n";
print MAIL "-" x 75 . "\n\n";
print MAIL "title: $title\n";
print MAIL "\n\n$poem\n";
print MAIL "posted on $datee from $ENV{'REMOTE_ADDR'}.\n";


close MAIL or bail("cannot close $MAIL: $!");

}


and then at the top of my file, i have:


# $mailprog defines the location of your sendmail
# program on your unix system.
$mailprog = '/usr/sbin/sendmail';


and yes, you have to have a mail program to mail it. if you want, once you get your script setup the way you want it (no more changes needed) you could give it to me and i could put it on my server and you could just have your form direct it there. or do some research on free unix shell accounts on places and see if they have mail proggies on them (make sure they let ya use cgi scripts.. hehe which is probably less than nill).

you might be in over yer head, but ah well, hehe. i'm still fighting over regexps ;o)

lates,

~kyle

VRay
02-25-2001, 01:09 AM
Thank for sticking with me, fandalem. I am understanding the submission of the emails part of this, but it is the gathering of the info and listing it that I am struggling with. I want to be able to have all the results of the emails, ie the body, in one long listing on page. Is that what your script will do? Add each submission to the same file? So when the time comes all i have to retrieve is the one page or file with all the relevant details on it? Any chance you could email me the pl file as the formatting is fooked up no matter what i do... Thanks again, I am gonna need help here, you need some work?