Create CSV on GravityForms submission
function populate_csv( $entry, $form ) {
//Headers info
$headers = array('Nominee', 'Reason1', 'Reason2', 'Reason3', 'Justification');
//Build form data
$data = array(
'Nominee' => rgar( $entry, '1' ),
'Reason1' => rgar( $entry, '4.1' ),
'Reason2' => rgar( $entry, '4.2' ),
'Reason3' => rgar( $entry, '4.3' ),
'Justification' => rgar( $entry, '3' ),
);
// check if the file exists or not to determine if headers are needed
$headersNeeded = !file_exists('Nominations.csv');
//Open or Create CSV File
$fh = fopen('Nominations.csv', 'a');
// if headers are needed, add them
if ($headersNeeded){
//Create headers
fputcsv($fh, $headers);
}
//Populate the data
fputcsv($fh,$data);
//Close the file
fclose($fh);
}
add_action( 'gform_after_submission_11', 'populate_csv', 10, 2 );