Web form to CSV via email?

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: [Jason] Web form to CSV via email?

By Toledoh - December 13, 2010

That's better - thanks Jason!

One thing though, an email is fired off as soon as you land on (or refresh) the page, not only when you "submit" the form.

Any ideas?
Cheers,

Tim (toledoh.com.au)

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)