I'm working with an existing Formmail script and trying to get multiple messages to port to a single file. In this case, sending the name, email, location, etc. fields for each sender to a single .csv file.
Any recommendations?
Hey, thanks, toon. I'll check it out.
Ah. They start off talking about db solutions, but move on to attached csv files. I need to collect data at a single source that's exportable in csv format rather than getting a csv file for each email. Sorry if I was unclear.
I'm not sure what Formmail is, but if you explain a small bit clearer what you want I might be able to help. Where would the source of the emails be coming from? Does the data already exist and if so, where?
Ah, I'm working a contact form on a website. The contact form is an extensive questionnaire, really, with information submitted by the website user. I need to collect that data into one file, which may be a database. The data needs to export to csv so that the basic contact info (name, email, etc.) can be stripped out and uploaded to an email list. Does that make sense?
Can you set up a MySQL database, and have the form submit to that?
That should do the trick, all you need to do is change (or add to) the variable names in @variables (the names of your form items) and the name of your csv file.Code:#!/usr/bin/perl -w use strict; use URI::Escape; use Fcntl qw(:flock); use CGI qw(:all); # Export all CGI functions into the current package my @variables = qw(name email comments); my $csv_file = "comments.csv"; sub printPage{ my $message = shift; print<<EOF; <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PERL Form</title> <link rel="stylesheet" href="index.css" media="screen" /> </head> <body> $message </body> </html> EOF exit(0); } ################################################################################################################## print header; my ($output, $sem); foreach my $item(@variables){ printPage("We were unable to process your comments due to the omission of '$item'") unless defined param($item); $output .= uri_escape(param($item)) . ","; } open(my $fh, ">>$csv_file") || die "Coulod not open comments.csv: $!"; print $fh substr($output, 0, length($output)-1) . "\n"; close($fh); printPage("Thank you for your comments."); sub get_lock{ open($sem, ">semaphore.sem") || die "Could not create semaphore file: $!"; flock($sem, LOCK_EX) || die "Lock failed: $!"; } sub release_lock{ close($sem); }
The output is URI escaped so you won't get input such as "Hi, my name is John" affecting the comma seperation in your CSV file.
Any questions just ask.
Regards
Carl
Last edited by Scriptage; 02-01-2009 at 05:28 PM. Reason: Disappearing HTML
Check the forum often for the latest design announcements. Everything from graphic design and web design, to films and music. Estetica is a great place for people to get together and help each other out.
Bookmarks