data['nachname-eltern'] . ";" . $form->data['strasse-nr'] . ";" . $form->data['plz-ort'] . ";" . $form->data['telefon'] . ";" . $form->data['e-mail'] . ";" . $form->data['geburtstag'] . ". " . $form->data['geburtsmonat'] . " " . $form->data['geburtsjahr'] . ";" . $form->data['moegliche-kurse'] . ";" . $form->data['sommerintensivkurs'] . ";" . $datum . "\r\n" ; // saving it in the file $file = fopen ($filepath . $filename, 'a'); fwrite ($file, $csv_row); fclose ($file); // add the attachement to the form array $form->files['csv'] = array( 'name' => $filename, 'original_name' => '', 'path' => $filepath.$filename, 'size' => '', 'link' => str_replace(JPATH_SITE.DS, JURI::root(), $filepath.$filename) ); ?>The fields 'moegliche-kurse' and 'sommerintensivkurs' are checkboxgroups and in the Excel it only shows "Array" instead of the content. I have no idea how i should add the foreach statement or something similar. All values in the Array should be in the same column.A second Problem are the letters ä, ö an ü. They are show as ö in Excel. I think something with encoding?Thanks for any suggestions."> Send an email with the form data as a csv attachement - Forums

Forums

Send an email with the form data as a csv attachement

The_Surfman 24 Aug, 2014
Hello

The data from the form should be send me by email as a csv so i can open it in Excel.
This works fine with normal fields but not with Arrays (checkboxgroup).
I added this code to the custom php code before email:
	<?php
	// date and time
	$timestamp = time();
	$datum = date("d-m-Y",$timestamp);
	
	// some variables
	$filename = 'kischwi';
	$filepath = 'tmp/';

	$filename = $filename . '.csv';
	
	// creating the CSV row
	$csv_row = $form->data['vorname-eltern']
	 . ";" . $form->data['nachname-eltern']
	. ";" . $form->data['strasse-nr']
	. ";" . $form->data['plz-ort']
	. ";" . $form->data['telefon']
	. ";" . $form->data['e-mail']
	. ";" . $form->data['geburtstag'] . ". " . $form->data['geburtsmonat'] . " " . $form->data['geburtsjahr']
	. ";" . $form->data['moegliche-kurse']
	. ";" . $form->data['sommerintensivkurs']
        . ";" . $datum
        . "\r\n" ;
	// saving it in the file
	$file = fopen ($filepath . $filename, 'a');
	fwrite ($file, $csv_row);
	fclose ($file);
	
	// add the attachement to the form array
	$form->files['csv'] = array(
	  'name' => $filename,
	  'original_name' => '',
	  'path' => $filepath.$filename,
	  'size' => '',
	  'link' => str_replace(JPATH_SITE.DS, JURI::root(), $filepath.$filename)
	);
	?>


The fields 'moegliche-kurse' and 'sommerintensivkurs' are checkboxgroups and in the Excel it only shows "Array" instead of the content. I have no idea how i should add the foreach statement or something similar. All values in the Array should be in the same column.

A second Problem are the letters ä, ö an ü. They are show as ö in Excel. I think something with encoding?

Thanks for any suggestions.
GreyHead 25 Aug, 2014
Hi The_Surfman,

Add a Handle Arrays action before the Custom Code to convert the arrays to comma separated strings.

And yes, the second problem is a Character set problem. Opening the file using the Excel Insert Text command should let you correct that.

Bob

PS ChronoForms does have an Export CSV action that will let you export all or selected records in a CSV file.
This topic is locked and no more replies can be posted.