Link to home
Start Free TrialLog in
Avatar of jamaica
jamaica

asked on

Script that can take form results and put it in a csv file and then email form results

I'm at my wits end with this script that I'm using but unable to get it to successfully email the form results to recipient list. If you go to https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=perl&qid=20311313 you will see the question posted there but still unresolved.

A brief on what I'm trying to accomplish.

I use a Perl script that will take users input from an html form. The perl script takes the form results and put it into a comma-separated flat database (csv file). I need to get the form results emailed to a recipient list, so I use $mailresults and point it to use the basic FormMail.pl as the form emailer but I keep getting into a "bad referer" problem ... Please read https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=perl&qid=20311313 and you will see the problem in details.

I've decided to post here to see if someone may be able to help, or come up with a better cgi script that'll handle emailing the form results to the recipients and updating the flat-comma-separated-database (csv file) with the results entered from the form.

If any one should have any issue with the post in the Perl fora and think I should resolve it first before getting any successful answers here, I'll close/award points/whatever ...

Thanks for the time and input.
-jamaica-
Avatar of samri
samri
Flag of Malaysia image

jamaica,

I have looked at the thread, and to be honest, I tend to get "lost" halfway.

So, I would prefer to start from fresh.

You have a page, where people would fill up the form and submit the form.  These data would be appended to a flat csv file.

At this point, did you want the scripts to mail the content of the data, and write it to the csv file, or write to csv file, and mail the whole file.

For example, you form would have: username, password, DOB, and the csv would look like;
---
samri,samri1234,19700101
jamaica,jamaicapassword,20000101
name,password,dateofbirth
---

Let say a user fill's up a form;
newuser,newpassword,111122333

Do you wan to information to be mailed to webmaster@yuorsite.com, upon clicking "submit", and the data is appended to the csv file.  OR, update the csv, and send all the content of the csv.

-Apology if this causes you to repeat the whole thing all over.  I haven't got a chance to try FormMail.  I heard that it's quite popular, but I would rather work something from scratch.

cheers.
Avatar of jamaica
jamaica

ASKER

Yes,this is exactly how I want the form to be done...

"the info information (entered in the form) to be mailed to webmaster@yuorsite.com, upon clicking "submit", and the data is appended to the csv file."

I use readcsv.pl to convert the csv into html and the link is sent in the mailer to the recipient(s).

Thank you so much for your help!
Jamaica,

Just give me some time to work it out.  I should come it with a rought scripts and hopefully it would work for you.

--(now I need to go to bed :(
Jamaica,

Just give me some time to work it out.  I should come it with a rought scripts and hopefully it would work for you.

--(now I need to go to bed :(

and hopefully, somebody else might be able to help too :)
Avatar of jamaica

ASKER

thank you samri, I need help bad!
Jamaica,

Apology for being so slow on this.  After going thru the original thread, it looks like lexwern has tried to work on the FormMail, but still no luck on you side.

-- Some comments, from the Original Question thread.

I decided to add the following line
require='usr/local/opt/abcxyz/abc.xyz.com/cgi-bin/FormMail.pl

This line executes FormMail.pl and emailed the form's results BUT it did not write the results to the csv file.
I got an error from the perl script that handles the csv file that the script was executed from html.  I have a print "Content-type: text/html","\n\n"; in the csv.
---

So it does work (mail got sent out) when you use "require" approach.

Could you try to add the "require" line, after you call the function to modify the csv.  Personally, I used to come across a situation where the FORM Data is missing after calling some perl modules (via use statement).

Another option is to assign the FORM data (that needs to be written to the csv explicitly.

I would say it's much straight forward to debug the csv printing than formmail at this point.

give it a shot.
Avatar of jamaica

ASKER

Yes, when I used "require" the mail got sent but the csv wasn't created.

Well, it has now turned out that the email notification is needed when the user selects a specific checkbox, e.g., there's a "Yes|No" checkbox on the form. If the user selects "No" then an email notification needs to be sent to a recipient notifying that the client selected "No" and immediate follow-up can be done at that point ...

My brain is fried right now and I can't think of an approach to take with that ... do a CGI script that'll send out an email notification if "No" checkbox is selected?  That's a whole different can of worms now.
jamaica,

I bet you must be almost giving up :(

Well, we know that the email notification is needed only when the check-box is "checked".  I think it is possible to examine the content of passed variable, an only send email if the radio button is checked.

Avatar of jamaica

ASKER

No, have not given up but I've found a dirt cheap way to do it!

I inserted this into the perl script that creates the csv
===== THIS IS INSERTED IN THE create csv ====

open (MAIL, "| /usr/lib/sendmail -oi -n -t" );
print MAIL <<MAIL_MESSAGE;
To:myemail\@whatever.com
From:you\@wherever.com
Subject: Just to notify

whatever goes here and it is sent in rich text format

MAIL_MESSAGE

close MAIL;
==========================

The dirt cheap way is using MSE-Exchange to auto-fwd the notification mail to the recipient(s). The rules wizard allows me to specify by subject, or look for text in the body and forward the notification to anyone I need it to go to. The main thing is the csv is converted to html and there's a link to the html page in the notification mail.

Maybe I should close this thread then?

I'll be back here later in the day and close with "jamaica has found a resolution for the question"
Jamaica,

Yup.  Since you already got a "working" solution, there is no point in keeping the Q open, unless you are still waiting for a much "cleaner" solution.  

At this point, since you had "solved" your own problem, and you cannot "award" yourself the pts, you could request for a deletion to this question.

Alternately, you request for a refund to your pts from Community Support (https://www.experts-exchange.com/commspt/) since that is the only way to keep the Q in PAQ.  This is better since other members could search the PAQ later.

https://www.experts-exchange.com/commspt/

cheers.
Avatar of jamaica

ASKER

Deletion request will be done.

Thank you again samri for your time. You and many others are the reason why I love this board, your selfless, timeless effort to make suggestions and help resolve a technical problem for another person!
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No prob.

That is the reason why we are all here.  To help each other (gee.. do I sound like a preacher :)

cheers.