OK. I figured this out on my own in the event it's helpful to someone else... Step 1: Create a child theme. You can do this manually or use a plugin. I used: https://wordpress.org/plugins/child-theme-configurator/ Step 2: Place the following code in the functions.php file.
// Apply a Formidable Forms view for the attached PDF in email
add_filter( 'frm_pdfs_email_attachment_args', 'add_view_to_attached_pdf', 10, 2 );
function add_view_to_attached_pdf( $pdf_args, $args ) {
if($args['form']->id ==5) { //change 5 to the ID of the form
$pdf_args['view'] = 2; // ID of view.
$pdf_args['id'] = $args['entry']->id; // Do this to show the detail view, otherwise, it shows the listing view.
return $pdf_args;
}
}
//Customize the PDF Name
add_filter( 'frm_pdfs_email_attachment_args', 'change_attached_pdf_file_name', 10, 2 );
function change_attached_pdf_file_name( $pdf_args, $args ) {
// Use the actual numeric field ID here instead of 'field_id'
$field_id = 1; // This is the ID of the field you want to include in the filename
$field_value = ''; // Default to an empty string if the field value is not found
if ( isset( $args['entry']->metas[$field_id] ) ) {
$field_value = $args['entry']->metas[$field_id]; // Fetch the field value
}
// Append the field value to the filename
$pdf_args['filename'] = 'Stuff-' . $field_value; // Change 'Stuff-' to anything you want
return $pdf_args;
}
Pretty simple actually.
Thanks for this, it's almost working for me. Not sure what I'm doing wrong. It now attaches the custom pdf to my emails but for some reason the pdf includes the information twice. It displays all the info and then at the end it displays it all again - exact duplicate. Very weird. Since you seem to be knowledgeable I wondered if you had any insights about why this might be happening?
Sorted!
Hi - sorry to bug you but I'm hoping you can give me some guidance on how I get this code to work for multiple forms and views. I have more than one form and have built views for each of them but I don't know how to adjust the code so that they all work. I can only get it to work for one. Thanks in advance.
Please login or Register to submit your answer