Skip to content

Instantly share code, notes, and snippets.

@BFTrick
Last active August 25, 2020 21:13
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BFTrick/535b611a52c3b6791996 to your computer and use it in GitHub Desktop.
Save BFTrick/535b611a52c3b6791996 to your computer and use it in GitHub Desktop.
A more customized Ninja Forms PDF Form Submissions template
<?php
/**
* PDF Included With Form Submission
*
* @author Patrick Rauland
* @version 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?>
<html>
<head>
<link type="text/css" href="pdf.css" rel="stylesheet" />
<link type="text/css" href="../../../themes/your-theme/pdf.css" />
</head>
<body>
<header>
<img src="../../../themes/your-theme/logo.png"/>
</header>
<div id="main">
<p>Hi <?php echo $fields[6]['value'];?> <?php echo $fields[23]['value'];?>!</p>
<p>Thanks for filling out our form. We'll respond to you shortly.</p>
</div>
</body>
</html>
@davidallenlewis
Copy link

@uniondesign

May I know where you added that code?

I put it at the top of my pdf.php template file

@davidallenlewis
Copy link

Does anyone know how to get the form submission ID in a custom PDF template? You can use the filter:

add_filter( 'ninja_forms_submission_pdf_fetch_sequential_number', '__return_true' );

And that will add it to the DEFAULT template which just appends it to the start of the $table string that the default template uses, but there doesn't seem to be any way to get it into the custom template. I can use get it AFTER the form has been submitted and saved to the database and then you go to Ninja Forms > Submissions and export the PDF... but not on the initial submission for the PDF that gets emailed.

@suzannezc
Copy link

suzannezc commented Oct 17, 2019

Is there a trick for identifying the form number in a multi-site situation?

Thank you to the previous commenters for the other tips. :)

@suzannezc
Copy link

The trick that appears to be working for me is using site_url() to determine the site url and then matching it on the site url and the form number. if site_url() is my site, and form is my form_ID, then...

@leyannots
Copy link

Buenas tardes! Hola a todos. I need help! I have 2 forms, but only one pdf.php, i need 2 forms, and, 2 pdf templates, understand me? Thanks!

@baas411
Copy link

baas411 commented Jul 2, 2020

Buenas tardes! Hola a todos. I need help! I have 2 forms, but only one pdf.php, i need 2 forms, and, 2 pdf templates, understand me? Thanks!

Use if else conditions to display the correct data for each form.

<?php if ( $form_ID == 1 ){ echo $fields[field_key_value_form1]['value']; } elseif ( $form_ID == 2 ) { echo $fields[field_key_value_form2]['value']; } else { echo $table; } ?>

@kapil247
Copy link

@baas411 i have the same issue as leyannots of multiple forms and want to have customized pdf for each one. please explain a little more in detail as i m not well versed in php. thanks

@baas411
Copy link

baas411 commented Aug 14, 2020

The if/else renders content for the pdf based on the id of the form. So if the form has id 1 then echo field_key_value_form1.
( $form_ID == 1 ) is the id of the ninja form.
field_key_value_form1 is the value from the form field (find it in ninja forms)
etc

@dustylavender
Copy link

dustylavender commented Aug 25, 2020

Does anybody know all of the available values that are possible or how they relate to the merge tags?

The "label" tag in this shows me label for the radio field, but with the merge tag, {field:q1:label} shows the selected radio label under options. Is it possible to grab that data on this?

Example
I have a radio select with 4 options; Fully Met, Partially Met, Not Met and N/A. Each of those options have different values. The code shows the radio value, not the radio label.

I'd like to pull that Label to the PDF vs the radio value.
Screen Shot 2020-08-25 at 5 10 40 PM

Bonus points question:
Has anybody successfully pulled a calculation onto the PDF form? My PDF needs to show a calculation value from the form...it is basically a quiz that our users take and I need to report the score. The merge tag for that is {calc:scoreval}.

Many thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment