+ Reply to Thread
Results 1 to 8 of 8

Thread: Form to CSV recommendation sought

  1. #1
    Idiosyncratic Member ;) likethegoddess's Avatar
    Join Date
    May 2008
    Location
    San Francisco, Calif.
    Posts
    802

    Form to CSV recommendation sought

    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 the arts
    Portfolio | Twitter | FriendFeed


  2. #2
    Netvibes is an Addiction™ Toon's Avatar
    Join Date
    Jan 2007
    Location
    Sheffield, UK
    Posts
    23,645
    Blog Entries
    12

  3. #3
    Idiosyncratic Member ;) likethegoddess's Avatar
    Join Date
    May 2008
    Location
    San Francisco, Calif.
    Posts
    802
    Hey, thanks, toon. I'll check it out.
    likethegoddess design for the arts
    Portfolio | Twitter | FriendFeed

  4. #4
    Idiosyncratic Member ;) likethegoddess's Avatar
    Join Date
    May 2008
    Location
    San Francisco, Calif.
    Posts
    802
    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 the arts
    Portfolio | Twitter | FriendFeed

  5. #5
    aka sionnach iandevlin's Avatar
    Join Date
    Aug 2008
    Location
    Cambridge, UK
    Posts
    2,042
    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?

  6. #6
    Idiosyncratic Member ;) likethegoddess's Avatar
    Join Date
    May 2008
    Location
    San Francisco, Calif.
    Posts
    802
    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 the arts
    Portfolio | Twitter | FriendFeed

  7. #7
    Dowsett Designs vdowsett's Avatar
    Join Date
    Mar 2008
    Location
    Overland Park, Kansas
    Posts
    995
    Can you set up a MySQL database, and have the form submit to that?

  8. #8
    likes chips. Scriptage's Avatar
    Join Date
    May 2008
    Location
    Yorkshire
    Posts
    2,758
    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);
    }
    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.

    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

+ Reply to Thread

Similar Threads

  1. Movie recommendation service
    By Harry in forum Off Topic
    Replies: 2
    Last Post: 06-11-2008, 03:38 PM
  2. How to create a form?????
    By PosterManiac in forum General Web Design Forum
    Replies: 3
    Last Post: 17-05-2008, 02:44 PM
  3. PHP Form
    By ohio in forum CSS Forum
    Replies: 3
    Last Post: 06-12-2007, 01:53 AM
  4. Replies: 0
    Last Post: 16-11-2007, 08:45 AM
  5. Form Help
    By drewbie_wan in forum Programming Forum
    Replies: 1
    Last Post: 07-09-2007, 08:32 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


The Graphics Forum Web Design Stuff Free Decent Downloads Free Quality Wallpapers Graphics Forum Free Vista Themes
The Top The Best Images Tech Talk 247 Logo Design - $149 Affordable Stock Vector Illustrations Creativecurio - Design Blog Graphic Design Advertising

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.



Web Hosting - UK Web Hosting services for business or personal website hosting needs.

Dedicated Servers - A full range of Managed Dedicated Server solutions suitable for all your requirements.

Graphic Design Blog | Web Design Forum | Graphic Design and Print Forum | Graphic Design Links | Advertise On This Site

Web Design UK | Vision.To Design | Leaflet Printing | Estetica Design Forum's Privacy Policy

Flyer Printing | Photography Blog | Design Forum Links | Logo Design | Graphic Design Social Network | Logo Design

Graphic Design Tutorials | Logo Designer | UK Logo Design Studio | Land for sale | Vector Art Blog | Leaflet Printing

Free Web Hosting | Custom Logo Design - $149 Only | Affordable Print Design Templates | Small Business Logo Design | Company Logo Design

Logo Design Service | Logo Design Firm | Logo Design Reseller | Custom Logo Design | Letterhead Printing | Flyer Printing | Business Card Printing

Printing | Leaflet Printing | Online Backup | T-Shirt Printing | Personalised Mugs | Canvas Printing | Free Web Hosting Comparison Site