![]() |
|
|||||||
| Programming Forum Web and Software Programming Forum - Java, PHP, SQL etc. |
|
|
![]() |
|
|
LinkBack (1) | Thread Tools | Display Modes |
|
||||
|
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?
____________________________
likethegoddess design for musicians and non-profits Twitter | RSS | Google Reader | Facebook | Flickr | Pandora | Last.fm |
|
|
|
||||
|
____________________________
Colour Printing and Integrated Cards || Graphic Design, Web Design UK || Logo Designer - Logo Design || Graphic Design Blog || Logo Design Logo Designer || Integrated Labels & Cards || Logo Design || Graphic Design Links || Web Design Rotherham UK || Logo Design UK || Web Design UK
|
|
||||
|
Hey, thanks, toon. I'll check it out.
____________________________
likethegoddess design for musicians and non-profits Twitter | RSS | Google Reader | Facebook | Flickr | Pandora | Last.fm |
|
||||
|
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.
____________________________
likethegoddess design for musicians and non-profits Twitter | RSS | Google Reader | Facebook | Flickr | Pandora | Last.fm |
|
||||
|
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?
____________________________
likethegoddess design for musicians and non-profits Twitter | RSS | Google Reader | Facebook | Flickr | Pandora | Last.fm |
|
||||
|
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 04:28 PM. Reason: Disappearing HTML |
![]() |
|
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Movie recommendation service | PR Design | Off Topic | 2 | 06-11-2008 02:38 PM |
| How to create a form????? | PosterManiac | General Web Design Forum | 3 | 17-05-2008 02:44 PM |
| PHP Form | ohio | CSS Forum | 3 | 06-12-2007 12:53 AM |
| Mobile/Web Designer Sought For London-Based Social Networking Application | Snappl | Design Forum Employment | 0 | 16-11-2007 07:45 AM |
| Form Help | drewbie_wan | Programming Forum | 1 | 07-09-2007 08:32 AM |