Send Custom PDF as an Attachment

By: S F | Asked: 02/22/2024
ForumsCategory: General questionsSend Custom PDF as an Attachment
S F asked 2 months ago
Perhaps I am missing something. I understand you can click a download link to get a custom pdf based upon a view. However, is there a way to have the custom pdf automatically sent as an attachment in a response email? In the actions section, selecting the pdf attachment just sends the form entries as a pdf attachment, not the custom pdf. I can't seem to find where I would direct it to my custom pdf format and use that to send as an attachment. Any help would be much appreciated. Thanks.
2 Answers
S F answered 2 months ago

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.

S F answered 1 week ago
Nothing like forgetting how to do this..coming here to search for a possible answer...and realizing I solved this once before. LOL 

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right