Web form to CSV via email?

By Toledoh - December 8, 2010 - edited: December 8, 2010

Hey guys.

I've got some pretty large forms that need to be filled out on a client site. Is it possible to utilise (or not) the CSV plugin to capture data from a form and then email that data to a recipient as an attached CSV file?

I'm not sure I really want to build a CMSB table for it, as the data doesn't really need to be stored - it's being re-enterred into a few off-line systems.

ALSO: is there any plans for a form builder / plugin?
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Web form to CSV via email?

By Chris - December 9, 2010

Hi Tim,

You can do this with a little PHP code, and the csvExport plugin will make it a little easier. How about this code?

$csv = '';
$csv .= implode(', ', array_map('_csvExport_escapeAsCSV', array_keys($_REQUEST))) . "\n";
$csv .= implode(', ', array_map('_csvExport_escapeAsCSV', array_values($_REQUEST))) . "\n";

sendMessage(array(
'from' => "from@example.com",
'to' => "to@example.com",
'subject' => "Enter subject here, supports utf-8 content",
'text' => "Text message content",
'attachments' => array(
'form.csv' => $csv
)
));


Please let me know if you have any questions.

P.S. Yes, there are plans for a form builder plugin, but I don't think they're near-future plans just yet. Don't hold your breath for its release, but we'll welcome any ideas you may have on such a plugin! :)
All the best,
Chris

Re: [chris] Web form to CSV via email?

By Toledoh - December 11, 2010

Thanks Chris!

Almost there... the email comes through, with the CSV attached, but there's no content in the CSV...
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Web form to CSV via email?

By Chris - December 11, 2010

Hi Tim,

Can you post your source code?
All the best,
Chris

Re: [chris] Web form to CSV via email?

By Toledoh - December 11, 2010

It's pretty ugly...
Cheers,

Tim (toledoh.com.au)
Attachments:

test_014.php 17K

Re: [Toledoh] Web form to CSV via email?

By Jason - December 13, 2010

Hi Tim,

The issue is right after you write a record to the database, you empty out the $_REQUEST array:
// display thanks message and clear form
$alertsAndErrors = "Thanks, we've added that record!";
$_REQUEST = array();


So when the script runs the CSV code below this, there is no data to put in the file. Try removing that last line.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Toledoh] Web form to CSV via email?

By Jason - December 13, 2010

Hi Tim,

Try putting your csv code inside your if statement, right under where you add your record to the database:

$recordNum = mysql_insert_id();

// display thanks message and clear form
$alertsAndErrors = "Thanks, we've added that record!";
$csv = '';
$csv .= implode(', ', array_map('_csvExport_escapeAsCSV', array_keys($_REQUEST))) . "\n";
$csv .= implode(', ', array_map('_csvExport_escapeAsCSV', array_values($_REQUEST))) . "\n";

sendMessage(array(
'from' => "tim@forrest.id.au",
'to' => "tim@toledoh.com.au",
'subject' => "Application Form",
'text' => "Text message content",
'attachments' => array(
'form.csv' => $csv
)
));
}


Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Web form to CSV via email?

By Toledoh - December 13, 2010

That's it... thanks Jason!
Cheers,

Tim (toledoh.com.au)