Duplicating a function for Custom PDF in email

By: Barbara Smith | Asked: 04/30/2024
ForumsCategory: Code HelpDuplicating a function for Custom PDF in email
Barbara Smith asked 3 months ago

I posted this in the general questions but it's getting very technical (for my limited experience) so I thought posting in CODE HELP might be a better option. I have multiple forms that each have a View created for custom PDF attachments in emails.  Currently using this style shortcode [frm-pdf view=574 entry="[id]" public=1] it is using the View layout for the Download PDF link that appears on the confirmation landing page for BOTH forms (see screenshots) but it is only sending the View layout PDF as email attachments for form ID7.  Form ID6 is still sending the standard layout and ignoring the view layout (screenshots attached for this as well).  Here is the code I currently have in my functions.php file: 

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 ==6) { //change 5 to the ID of the form
         $pdf_args['view'] = 554; // 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;          
    }
}
add_filter( 'frm_pdfs_email_attachment_args', 'add_view_investius_pdf', 10, 2 );
function add_view_investius_pdf( $pdf_args, $args ) {
    if($args['form']->id ==7) { //change 5 to the ID of the form
         $pdf_args['view'] = 574; // 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;
   }
}

Can anyone tell me where I am going wrong? I used the following links to try to work it out myself but I'm obviously doing something wrong: https://formidableforms.com/knowledgebase/formidable-hooks/#kb-duplicating-a-function https://formidableforms.com/knowledgebase/frm_pdfs_email_attachment_args/#kb-apply-a-view-for-the-attached-pdf

Attachments
1 Answers
Best Answer
Rob LeVineRob LeVine answered 3 months ago
I don't think you followed Bobby's suggestion completely. Honestly, I don't see why you can't do it all in one function as follows.
add_filter( 'frm_pdfs_email_attachment_args', 'add_view_to_attached_pdf', 10, 2 );
function add_view_to_attached_pdf( $pdf_args, $args ) {
	$args_set = false;
	switch($args['form']->id) {
		case 6:
			$pdf_args['view'] = 554;
			$args_set = true;
			break;
		case 7:
			$pdf_args['view'] = 574;
			$args_set = true;
			break;
		default:
			break;
	}
	if ($args_set) {
            $pdf_args['id']   = $args['entry']->id; // Do this to show the detail view, otherwise, it shows the listing view.
            return $pdf_args;          
	}
}
Barbara Smith replied 3 months ago

Thank you Rob, I'm so relieved I could cry - it is finally working with this code! You saved me 🙂

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