https://connect.formidableforms.com/question/category/code-help/duplicating-a-function-for-custom-pdf-in-email
Thank you. I sorted it out finally using the below code which seems to be working for now. I appreciate you taking the time to help me.
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;
}
}
You have a couple of options if you're wanting to do this over multiple forms/views.
Learn about and implement php arrays and foreach loops: https://www.w3schools.com/php/php_looping_foreach.asp
Or have a filter for each form/view (not the non-unique function names). For example:
add_filter( 'frm_pdfs_email_attachment_args_form10_view5', 'add_view_to_attached_pdf_form10_view5', 10, 2 );
add_filter( 'frm_pdfs_email_attachment_args_form12_view8', 'add_view_to_attached_pdf_form12_view8', 10, 2 );
...
Hi Bobby - thanks for trying to help me. I changed the code to the below to where I guessed I should for my form ID's and View ID's but it's giving me this error:
Syntax error, unexpected 'add_view_to_attached_pdf_form6' (T_STRING), expecting ')'
I changed the code you gave me to:
add_filter( 'frm_pdfs_email_attachment_args_form6_view554’, 'add_view_to_attached_pdf_form6_view554’, 10, 2 );
add_filter( 'frm_pdfs_email_attachment_args_form7_view574’, 'add_view_to_attached_pdf_form7_view574’, 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;
}
}
Entirely possible I made a mistake. I was really hoping that using this plugin would mean I wouldn't have to know how to write code 🙂
Please login or Register to submit your answer