While browsing the plug-in code I've found the filter 'frm_fields_for_csv_export' (https://formidableforms.com/knowledgebase/frm_fields_for_csv_export/) which actually is being used before attaching the CSV to an email. This is the code I eventually used to make it work.
add_filter( 'frm_fields_for_csv_export', 'sv_change_headers_for_csv_export', 10, 2 );
function sv_change_headers_for_csv_export( $fields, $args ) {
$target_form_id = 3; // change 220 to the ID of the form
if ( $target_form_id === (int) $args['form']->id ) {
// change 67 to your field ids, and the text to the new CSV headers
$matches = array(
67 => 'New name'
);
// Loops all $fields and changes the names of the fields that are exported to CSV
foreach ( $fields as $field ) {
if ( isset($matches[$field->id] ) ) {
$field->name = $matches[$field->id];
}
}
}
return $fields;
}
Glad you were able to resolve it and thanks for sharing the final solution.
I’m afraid this looks to be changing the headers of the CSV when exporting from a view (when exporting an entry from the admin). I need them changed in the email attachment right after an entry is submitted.
Please login or Register to submit your answer