title: Ninja Forms Custom PDF template returns an error
body: <p>I have created a custom pdf template for ninja forms pdf submission add on from the example provided here: <a href="https://www.speakinginbytes.com/2014/11/customizing-ninja-forms-pdf-submissions/" rel="nofollow noreferrer">https://www.speakinginbytes.com/2014/11/customizing-ninja-forms-pdf-submissions/</a></p>
  
  <p>So I placed a new pdf.php and pdf.css file inside a folder named "ninja-forms-pdf-submissions" in my child theme.</p>
  
  <p>This custom pdf template used to work perfectly before but now it's returning an error that says</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'fields' of undefined
  at n.submitErrors (front-end.js?ver=3.4.3:1)
  at _ (backbone.min.js?ver=1.2.3:1)
  at m (backbone.min.js?ver=1.2.3:1)
  at f (backbone.min.js?ver=1.2.3:1)
  at u.Channel.u.trigger (backbone.min.js?ver=1.2.3:1)
  at Object.error (front-end.js?ver=3.4.3:3)
  at i (jquery.js?ver=1.12.4:2)
  at Object.fireWith [as rejectWith] (jquery.js?ver=1.12.4:2)
  at y (jquery.js?ver=1.12.4:4)
  at XMLHttpRequest.c (jquery.js?ver=1.12.4:4)
  </code></pre>
  
  <p>Below is the template I created.</p>
  
  <pre><code>&lt;?php
  /**
   * PDF Included With Form Submission
   *
   * @author      Patrick Rauland
   * @version     1.0.0
   */
  
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  
  ?&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;link type="text/css" href="&lt;?php echo $css_path; ?&gt;" rel="stylesheet" /&gt;
      &lt;link type="text/css" href="../../../themes/swu-child-2/ninja-forms-pdf-submissions/pdf.css" rel="stylesheet"/&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;header&gt;
          &lt;img src="../../../uploads/2017/09/swu-logo-2.png"/&gt;
      &lt;/header&gt;
      &lt;div id="main"&gt;
          &lt;h1&gt;&lt;?php echo $title; ?&gt; (Report Answers)&lt;/h1&gt;
          &lt;p&gt;Hi &lt;?php echo $fields[317]['value'];?&gt; &lt;?php echo $fields[318]['value'];?&gt;!&lt;/p&gt;
          &lt;p&gt;Thank you for your completing our financial success health check. At SWU Group, we are here to provide stewardship with regards to all aspects of your financial life and success. In this report, you will see the areas in which you are doing well in your financial life and areas in which you can improve on. The SWU Group family office is here to help you both maintain the areas of your financial life where you are doing well and provide guidance and advice in the areas you need improvement on to achieve your financial success.&lt;/p&gt;
          &lt;p&gt;Please note that this report is not financial product advice and is intended to provide information only.  It does not take into account your investment objectives, financial situation or needs. You should assess whether the information is appropriate for you and consider talking to a financial adviser before making an investment decision. The information is taken from sources which are believed to be accurate but the SWU Group and its associated companies accepts no liability of any kind to any person who relies on the information contained in this report.&lt;/p&gt;
          &lt;p&gt;If you have any questions, please free to contact us:&lt;/p&gt;
          &lt;p&gt;Phone: (02) 9211 0228&lt;/p&gt;
          &lt;p&gt;Email:&lt;a href="mailto:financialsuccess@simonwu.com.au"&gt;financialsuccess@simonwu.com.au&lt;/a&gt;&lt;/p&gt;
      &lt;/div&gt;
  
      &lt;?php //echo $table; ?&gt;
  
      &lt;?php
          $defsuccscore = $fields[309]['value'];
          $debtstratscore = $fields[310]['value'];
          $budgetscore = $fields[311]['value'];
          $assetprotscore = $fields[312]['value'];
          $estateplanscore = $fields[313]['value'];
          $supannuationscore = $fields[314]['value'];
          $selfmanagedsupfundscore = $fields[391]['value'];
          $investmentscore = $fields[398]['value'];
  
          //echo $defsuccscore;
  
      echo "&lt;h2&gt;Definition of success&lt;/h2&gt;";
  
          if ($defsuccscore &gt;= 7.5) {
              echo '&lt;img src="../../../uploads/2018/01/check.png"/&gt;&lt;br/&gt;&lt;h3&gt;SATISFACTORY&lt;/h3&gt;&lt;p&gt;Having clear financial goals is very important for you to focus on, and it seems that you have these in place. That way, you know where you want to be and when, so well done! Whether it be a holiday once a year, saving for another investment property or simply saving aggressively to pay off your mortgage, the goal must be clear, measureable and timely. To ensure you are always motivated to achieve your goals, set some short, medium and long term ones. If you are 40 years old or above, one of the biggest goals you must have on your list is your retirement savings and how to maximise this through superannuation.&lt;/p&gt;';
          }
          else {
              echo '&lt;img src="../../../uploads/2018/01/cross.png"/&gt;&lt;br/&gt;&lt;h3&gt;NEEDS IMPROVEMENT&lt;/h3&gt;&lt;p&gt;This is an area you need to improve on. Goals are key to financial success. You need to define what success means to you and then attach goals to that definition. Whether it be a holiday once a year, saving for another investment property or simply saving aggressively to pay off your mortgage, the goal must be clear, measureable and timely. To ensure you are always motivated to achieve your goals, set some short, medium and long term ones. If you are 40 years old or above, one of the biggest goals you must have on your list is your retirement savings. Seeking out the professional advice of a financial adviser from the SWU Group can assist you in defining your financial success and goals to achieve it.&lt;/p&gt;';
          }
  
          echo "&lt;h2&gt;Debt Strategies&lt;/h2&gt;";
  
          if ($debtstratscore &gt;= 7.5) {
              echo '&lt;img src="../../../uploads/2018/01/check.png"/&gt;&lt;br/&gt;&lt;h3&gt;SATISFACTORY&lt;/h3&gt;&lt;p&gt;Well done, you seem to have a good understanding of how to manage your debt levels. Remember the importance of reducing your non-deductible debt first because this has the greatest impact to your after tax cash flow. Linking this back to financial goals, having a clearly defined timeline as to how you are going to pay down non-deductible debt is a great motivator to achieving financial success. With regards to your deductible debt, note that while it can be tax deductible, it still impacts your cash flow each month and that you won’t receive the benefits of this until you lodge your tax return after the end of the financial year (30 June each year). Deductible debt should also be continuously monitored and ensure you can afford to pay both principal and interest over the long term, not just the interest component.&lt;/p&gt;';
          }
          else {
              echo '&lt;img src="../../../uploads/2018/01/cross.png"/&gt;&lt;br/&gt;&lt;h3&gt;NEEDS IMPROVEMENT&lt;/h3&gt;&lt;p&gt;Debt can be both a good and bad thing and you may need help with managing it. If the debt is non-deductible which generally includes the mortgage of your principal place of residence (home) this is the type of debt you want to prioritise in paying off. Deductible debt are those which are used mainly for investment purposes (investment property, margin loans, and home equity loans). Interest payments can be tax deductible meaning that your after tax interest cost is generally less than what you actually pay each month. When considering taking on tax deductible debt, ensure you calculate your after tax interest cost vs your potential investment return to see if it is worthwhile to make the investment. Note that while this type of debt can be tax deductible, it still impacts on your cash flow each month and that you won’t receive the benefits of this until you lodge your tax return after the end of the financial year (30 June each year). You should make an appointment to see a financial adviser at the SWU Group to see if you have your debt under control and if there are ways to structure it to maximise tax efficiencies.&lt;/p&gt;';
          }
  
          echo "&lt;h2&gt;Budgeting&lt;/h2&gt;";
  
          if ($budgetscore &gt; 10) {
              echo '&lt;img src="../../../uploads/2018/01/check.png"/&gt;&lt;br/&gt;&lt;h3&gt;SATISFACTORY&lt;/h3&gt;&lt;p&gt;Budgeting is one of the most important elements of a long term financial plan. Without a budget, you don’t know if you are living within your means and if you can afford other things such as holidays, investments or other big purchases. It’s good to see that you are doing well in this area and that you have surplus income meaning your income is greater than your expenses. Budgeting is also good to ensure you are keeping track of how much you are saving and linking this back to your financial goals. Remember – every little bit you save in the short term, makes a big difference in the long term! Are you maximising your savings? If you would like to find out how to get the most out of your savings, contact us for a no obligation consultation.&lt;/p&gt;';
          }
          else {
              echo '&lt;img src="../../../uploads/2018/01/cross.png"/&gt;&lt;br/&gt;&lt;h3&gt;NEEDS IMPROVEMENT&lt;/h3&gt;&lt;p&gt;One of the first parts to any prudent financial plan is setting up a proper budget. This is an area which requires your attention. Budgeting allows you to clearly calculate if you are living within your means and if you can afford other things such as holidays, investments or other big purchases. One of the biggest problems we see is that many people have more expenses than income each month and end up taking on credit card debt which in the long term is clearly not sustainable. Even if you have surplus cash flow each month, are you maximising what you can do with it? You should make an appointment to see a financial adviser at the SWU Group to see how we can help you tailor a budget to suit your needs and assist you in achieving your financial success.&lt;/p&gt;';
          }
  
          echo "&lt;h2&gt;Asset Protection&lt;/h2&gt;";
  
          if ($assetprotscore &gt; 20) {
              echo '&lt;img src="../../../uploads/2018/01/check.png"/&gt;&lt;br/&gt;&lt;h3&gt;SATISFACTORY&lt;/h3&gt;&lt;p&gt;Asset protection which relates to protecting yourself through insurance is a key driver to financial success, especially later in life and more importantly in retirement. This is an area which you seemed to have adequately put in place. You still need to continuously review your current situation just like your investments to ensure what you have in place is still appropriate. This could mean that you may not have enough and need to increase the level of cover, or your needs may have decreased and by decreasing the sums insured, you could reduce the annual premiums which need to be paid. The way you could calculate your needs varies depending on how much debt you have as well as your annual expenses both of yourself and your family. Have you considered putting in place insurances to cover the partner in the family who does not work? Make an appointment to see one of our specialist financial advisers to see if this could increase your families ongoing asset protection needs.&lt;/p&gt;';
          }
          else {
              echo '&lt;img src="../../../uploads/2018/01/cross.png"/&gt;&lt;br/&gt;&lt;h3&gt;NOT SATISFACTORY&lt;/h3&gt;&lt;p&gt;Asset protection which relates to protecting yourself through insurance is a key driver to financial success, especially later in life and more importantly in retirement. This is an area which you require some improvement and review. Do you protect your car through insurance? Do you protect your home through insurance? Why? It\'s not because you hope that you will one day will have to claim on it, but if you do have an accident or a storm damaging your home, you know you don’t need to draw on your savings to rectify the damage. This applies the same for life and TPD (Total and Permanent Disablement), Income Protection and Trauma. The first and most crucial step is to calculate what your required cover should be and this will require the assistance of a good financial adviser. Furthermore, have you considered putting in place insurances to cover the partner in the family who does not work? Please contact us at the SWU Group to make a no obligation appointment to discuss how we can provide peace of mind to you and your loved ones.&lt;/p&gt;';
          }
  
          echo "&lt;h2&gt;Estate Planning&lt;/h2&gt;";
  
          if ($estateplanscore &gt; 10) {
              echo '&lt;img src="../../../uploads/2018/01/check.png"/&gt;&lt;br/&gt;&lt;h3&gt;SATISFACTORY&lt;/h3&gt;&lt;p&gt;Congratulations – it seems that you have most, if not all of your estate planning arrangements in place. No matter how you achieve your financial success, if you finally have assets leftover when you pass away, you would no doubt want to achieve two things. First and foremost – leave monies to your loved ones and secondly to reduce any disputes that could arise when estates are distributed to beneficiaries. Remember that even though you currently have estate planning arrangements in place, your circumstances will change which may mean that you need to update your arrangements. Also consider how much you paid to get your estate planning in place because as the saying goes - it is very true that you pay for what you get. Post office wills for example while cost effective, can contain many risks which without proper legal advice which in turn could risk your family’s financial future. Furthermore, have you structured your future estate in a way that is tax effective when it arrives in the hands of your beneficiaries? We are happy to review your estate plan as part of an initial consultation at the SWU Group. &lt;a href="#"&gt;Click here to see the range of estate planning services we can provide&lt;/a&gt;&lt;/p&gt;';
          }
          else {
              echo '&lt;img src="../../../uploads/2018/01/cross.png"/&gt;&lt;br/&gt;&lt;h3&gt;NOT SATISFACTORY&lt;/h3&gt;&lt;p&gt;Most people never consider estate planning as one component of achieving financial success but it most certainly is. It appears that you do need to address this area as it could be improved. The key point here is that no matter how you achieve your financial success, if you finally have assets leftover when you pass away, you would no doubt want to achieve two things. First and foremost – leave monies to your loved ones and secondly to reduce any disputes that can arise when estates are distributed to beneficiaries. While cost is always a consideration in putting an estate plan in place, note that if an effective plan is enacted, this will reduce dispute costs down the track. Short term cost for long term gain! We at the SWU Group have a pain free, effective solution for estate planning which will give you the peace of mind for you and your loved ones. &lt;a hre="#"&gt;Click here to see the range of estate planning services we can provide&lt;/a&gt;&lt;/p&gt;';
          }
  
          echo "&lt;h2&gt;Superannuation&lt;/h2&gt;";
  
          if ($supannuationscore &gt; 10) {
              echo '&lt;img src="../../../uploads/2018/01/check.png"/&gt;&lt;br/&gt;&lt;h3&gt;SATISFACTORY&lt;/h3&gt;&lt;p&gt;When asking the public what you have in place for your retirement most will answer with their superannuation. While retirement may be still a while away for you, it is good that you seem to be on top of things in this area. It’s great to see that you understand the power of consolidating your super into one account to potentially reduce overall fees. While structurally you are sound, do you effectively manage the investments within your superannuation? Are you taking on too much risk where you are increasing sequential risk, or taking on too little risk where you may not achieve your ultimate financial goal? As part of your initial consultation, we would review both the structure of your superannuation as well as the investments that form part of it. As superannuation law continues to change and evolve from year to year, we can help ensure you are executing the most tax effective strategy in place based upon your circumstances in managing your key retirement asset. We would love to assist you in achieving your financial success! &lt;a href="#"&gt;Click here to see the range of financial planning services we can provide and our investment philosophy&lt;/a&gt;&lt;/p&gt;';
          }
          else {
              echo '&lt;img src="../../../uploads/2018/01/cross.png"/&gt;&lt;br/&gt;&lt;h3&gt;NOT SATISFACTORY&lt;/h3&gt;&lt;p&gt;Effective management of your superannuation will be one of key elements to financial success. While retirement may be still a while away for you, it is important that you get on top of it as early as possible. The key reason for this, is that the earlier you put your super on the right track, the better off you could be in retirement. We see too many clients come to us just before they retire, and this is simply too late as they may not be able to contribute all the assets they want  into superannuation, or the strategy to most effectively manage their super would take at least 3-5 years before it is complete. Furthermore, do you know where you are now, and where you want to be when you retire? Given that superannuation law continuously changes and evolves, you should take up an ongoing advice arrangement with a trusted financial adviser to ensure that you are making the most of contribution strategies and investing your hard earned monies in the most appropriate way possible which is in line with your values as well as taking on a level of risk that you are comfortable with. Feel free to contact us at the SWU Group to arrange your initial no obligation consultation. &lt;a href="#"&gt;Click here to see the range of financial planning services we can provide and our investment philosophy&lt;/a&gt;&lt;/p&gt;';
          }
  
          echo "&lt;h2&gt;Self-Managed Super Funds&lt;/h2&gt;";
  
          if ($selfmanagedsupfundscore &gt;= 16) {
              echo '&lt;img src="../../../uploads/2018/01/check.png"/&gt;&lt;br/&gt;&lt;h3&gt;SATISFACTORY&lt;/h3&gt;&lt;p&gt;Self-Managed Super Funds (SMSFs) are one of the most complex structures used for investment purposes and if used correctly and appropriately it can be very effective. From a legal perspective, there are many traps which could lead your SMSF to become non-compliant which could lead it being charged the highest marginal tax possible. This is clearly an undesirable outcome, so it is good to see that you have a current trust deed, a well-documented investment strategy and understand how much it costs you per year to run the fund both from an investment advice perspective as well as accounting. It is important to regularly review your trust deed and investment strategy to ensure it is both appropriate for your needs as well as legally compliant. If you would like these documents reviewed, please feel free to contact us for a no obligation appointment.&lt;/p&gt;';
          }
          else {
              echo '&lt;img src="../../../uploads/2018/01/cross.png"/&gt;&lt;br/&gt;&lt;h3&gt;UNSATISFACTORY&lt;/h3&gt;&lt;p&gt;Self-Managed Super Funds (SMSFs) are one of the most complex structures used for investment purposes and if used correctly and appropriately it can be very effective. It must also be made very clear that because of its complexity, many of the regulations and laws which govern SMSFs are often breached leading to the potential of the fund being classed as non-compliant and could face heavy penalties including paying the highest marginal tax rate. We have only highlighted a few elements here including ensuring a current trust deed is in place, a well-documented investment strategy as well as understanding the costs of running your fund from year to year. Given there is at least one area where you either have overlooked or require assistance with, it is imperative that you contact your financial adviser and/or accountant for a review of your fund and personal circumstances. The SWU Group is also here to help, so please contact us for a no obligation review of your funds affairs.&lt;/p&gt;';
          }
  
          echo "&lt;h2&gt;Investments&lt;/h2&gt;";
  
          if ($investmentscore &gt; 30) {
              echo '&lt;img src="../../../uploads/2018/01/check.png"/&gt;&lt;br/&gt;&lt;h3&gt;SATISFACTORY&lt;/h3&gt;&lt;p&gt;Fantastic! You seem to be managing your investments reasonably well. It is very important to always find better ways of utilizing excess disposable income that is matched to your level of risk tolerance. Solely relying on your own home and superannuation is not a wise long term strategy to achieving your financial success. If you have a diversified investment portfolio, it is very important for you to review the portfolio regularly, whether it be shares, bonds, property or a combination of all of them. As markets change, so will the value of your investments along with its risk factors. One way to keep you on track and motivated with your investments and returns, is to set yourself lifestyle goals with associated timeframes. Always remember that with any investment, will come with associated level of risk, so it is wise to ensure that both sides are balanced out so that you can sleep easy! &lt;/p&gt;';
          }
          else {
              echo '&lt;img src="../../../uploads/2018/01/cross.png"/&gt;&lt;br/&gt;&lt;h3&gt;UNSATISFACTORY&lt;/h3&gt;&lt;p&gt;An investment portfolio that doesn’t include your home and superannuation is key to long term financial success. If you have completed a good budget (refer to earlier section), then you will be able to calculate any disposable income you may have that could go towards an investment portfolio. When you consider building an investment portfolio, you need to evaluate the level of risk you are willing to take on, and then to build a portfolio based upon that risk. This is only the beginning of the journey. Many believe in a set and forget strategy whereby once they invest, then they just leave it to grow – this is certainly not a wise path to go down. Investment markets change, risks can rise and fall, so you must ensure you regularly review your investments to ensure they are on track and that they have a reasonable probability of reaching your desired lifestyle goals. If you would like assistance in building your investment portfolio to achieve your financial success, feel free to make an appointment to see one of our financial advisers for a professional review of your circumstances.&lt;/p&gt;';
          }
  
      ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I've been struggling to find the error now as it used to work before from old versions of the PDF submission add on.</p>
  
  <p>Any help or advice on the custom template I created will greatly help.</p>
  
  <p>Thank you!</p>