Americas

  • United States

Web forms and CSV files

Opinion
Sep 06, 20042 mins
Enterprise Applications

We tried the FormMail modifications you suggested last week, and the data file was saved but the comma separated value format didn’t work. The data file contains copies of the FormMail e-mails rather than a simple table containing the values. How do we fix it?

We tried the  FormMail modifications you suggested last week , and the data file was saved but the comma separated value format didn’t work. The data file contains copies of the FormMail e-mails rather than a simple table containing the values. How do we fix it?

The instructions I provided create a text file containing copies of the FormMail messages with a CSV extension rather than a comma separated value table.

To extract and save only the submitted form field values to such a table requires parsing the name/value pairs out of the e-mail body and writing the table. The easy fix is to modify the stock FormMail.pl script to add a subroutine that uses the standard Perl CGI module for parameter parsing and writes comma separated data values to the file.

To use the CGI module, include the line: use CGI;To write an actual CSV string to the CSV file, use a statement such as:

foreach $p (CGI::param()) { print CSV "$p,"};

Depending on your original form, you might need to perform some validation to ensure that each line contains values from the proper field in each column.