Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Convert form data to csv and send as attachment

  1. #1
    Join Date
    Jan 2007
    Posts
    22

    Default Convert form data to csv and send as attachment

    Hi,

    First, FM is working and is a great script. The How-To pages cover how to create a csv formatted email, but not the other bits that I am trying to do. Russell has been patiently trying to help me do the following but probably since I am not experienced with php, I haven't been able to make it work.

    - FM processes the html form data and creates a separate csv file, this file NOT to be stored in a db.
    - FM automatically attaches the csv file to the email generated by FM, and does not include the data in the body of the email.

    My client then loads the csv file directly into their proprietary customer data base. The clients do not want the liability problems of storing sensitive customer info on their db, no matter how secure I can make it.

    I hope that someone has faced this requirement before and has some ideas on how to modify FM to do it.

    Regards from chilly New England

  2. #2
    Join Date
    Dec 2005
    Posts
    74

    Default Re: Convert form data to csv and send as attachment

    Doc,

    What exactly are you not able to make happen? Do you get the form email? Does the email have an attachment?

    George

  3. #3
    Join Date
    Jan 2007
    Posts
    22

    Default Re: Convert form data to csv and send as attachment

    Quote Originally Posted by GeoBrooks
    Doc,

    What exactly are you not able to make happen? Do you get the form email? Does the email have an attachment?

    George
    Hi George,

    I receive the form email. The text of the email uses the Plaintemplate that I created to send the data in csv format. But I don't want the form data in the body of the email, I want it only as an attachment in csv format. I will encode the attachment with Tectites encoder utilities. Does that make sense?

    Doc

  4. #4
    Join Date
    Dec 2005
    Posts
    74

    Default Re: Convert form data to csv and send as attachment

    Doc,

    All sounds good. The issue is then getting the csv attachment into your db? In short, the process is straightforward. Assuming you've saved the attachmet, with PHP you can:
    • open attachment, read contents
    • parse contents to variables
    • store variables in tables
    If you're interested in seeing one non-programmer's solution to the problem, send me a private message with your email address. I'll send you a copy of what I did for a local non-profit outfit.

    George

  5. #5
    Join Date
    Jan 2007
    Posts
    22

    Default Re: Convert form data to csv and send as attachment

    George,

    Sorry if my explanation was not complete. I actually don't want to store the csv in a db. The client only wants to have a csv file delivered to him as an attachment in his email. The csv file with his customer's personal info is then loaded into the client's application. Is there any hope in FM to do this?

    Doc

  6. #6
    Join Date
    Dec 2005
    Posts
    74

    Smile Re: Convert form data to csv and send as attachment

    Doc,

    Apologies for misunderstanding. It's pretty straightforward. My recollection may be incomplete, but the requirements include:
    • creating a csv text file where the first line has comma-delimited field names as expected by the end users application, the second line contains comma-delimited variables from the form. For example, the first line might begin "email",... and the second line begin "$email",...
    • store this csv template file in the templates directory identified in formmail.php.
    • refer to this template file in code like this:
    HTML Code:
    <input type="hidden" name="mail_options" value="PlainTemplate={csv template file}",{other options} />
    <input type="hidden" name="filter_options" value="Attach={attachment file name}" />
    <input type="hidden" name="filter" value="null" />
    There may be some minor pieces missing, but this'll get you going. It can't be too hard - I managed to make it work!

    Good luck

    George

  7. #7
    Join Date
    Jan 2007
    Posts
    22

    Default Re: Convert form data to csv and send as attachment

    George,

    Success! After adding your code snippet to the form, the email is sent with no text in the body and with a csv file attached. The csv file opens in Excel and it has the correct format as specified in the plain.csv template, so I assume it will load into the client's application. The next step for me is to add spam security and encode/decode (maybe Tectite's Captcha and en/decode) the csv file to keep hackers away from the sensitive info.

    With great relief that this is working and many many thanks for sharing your knowledge,

    Doc

  8. #8
    Join Date
    Feb 2007
    Posts
    82

    Default Re: Convert form data to csv and send as attachment

    <input type="hidden" name="filter_options" value="Attach=csv.csv,KeepInLine" />
    <input type="hidden" name="mail_options" value="HTMLTemplate=efileregis.htm,PlainTemplate=csv.csv,TemplateMissing=" />
    <input type="hidden" name="filter" value="null" />


    I have the above, and I get the email, in html, I also get the csv file, but my problem is that the csv when it opens in excel goes from row 1 to row 20, not filling in row 1 all the way to column 20. It also contains the field NAMES despite every formatting I can think of to strip the names.
    I just want a plain line of fields, separated by commas, so that the person getting the email can copy and paste it into a combined spreadsheet.
    does anyone know how to do this?

  9. #9
    Join Date
    Dec 2005
    Posts
    74

    Default Re: Convert form data to csv and send as attachment

    If I understand correctly, when you open the csv file in Excel you get a two cells: A1: contains all the field names that appear in your template file; and A2: contains all of the entries in a single cell.

    To get a single row of just the variables (and no field names above them) you can delete the first row of your template text file.

    To get each value in a cell, the separator in the text file needs to be the default separator in Excel. I would expect this to be a comma.

    I just did an experiment and got a single row of variables, each in a separate cell. My template text file begins: "$type","$email","$FirstName"...

    Hope this is useful.

    George

  10. #10
    Join Date
    Feb 2007
    Posts
    82

    Default Re: Convert form data to csv and send as attachment

    no, what I get is one column with 20 rows, with the 'FieldName: field' in each row.....but, my (blank) csv when opened, opens across one row, with 20 columns In fact no matter how I try to format the results, I get the field names included. I was able to get it in one line in html, comma separated results, but the field names tag along and muck up the results.

    one thing however, I do not have the quotes around each field, so am going to try that right now.
    I also have my file named with the extention csv...and I could never understand if I am supposed to have it named as csv or txt
    thank you so much for your thoughts and help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to Parse data from one Form to another
    By CliqAdam in forum FormMail Subscription Support
    Replies: 5
    Last Post: 01-Dec-2004, 12:57 AM
  2. Adding Attachment Variables
    By Bella in forum FormMail Subscription Support
    Replies: 1
    Last Post: 12-Apr-2004, 09:43 AM
  3. POST form data as well as email
    By zippy in forum FormMail Subscription Support
    Replies: 20
    Last Post: 24-Jan-2004, 04:29 PM
  4. not seeing form data
    By brownie in forum FormMail Subscription Support
    Replies: 6
    Last Post: 19-Jan-2004, 01:37 AM
  5. Help trying to set up a form to email and send info to file
    By rridsdale in forum FormMail Subscription Support
    Replies: 1
    Last Post: 14-Jan-2004, 02:38 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
  •