Cannot get custom fields to work

I have installed a test version of 1.5.0, taking a backup of my database then essentially doing a clean install and then copying my templates and other assets over but I am still facing the same problem I had when I tried Beta 3 - I cannot get the custom fields to show on my invoice (mainly because I do not understand the new format and I’m not sure if the wiki actually refers to the new format).

My existing fields seem to have migrated over fine, but to be sure, I have set up a brand new field called “TEST” under the Invoice node and still cannot work it out.

The following code used to show the contact name on my invoice (if one was present) now I just get a PHP error;


<?php if ($invoice->client_custom_contact) {
  echo 'FAO: ' . $invoice->client_custom_contact . '<br/>';
} ?>

In my config, the above field (as migrated by 1.5.0) is configured as follows;

Table: Client
Label: Contact
Type: Text
Order: 999

In my invoice which I am using to test this, “Contact” has a value of “TEST”.

I have added the

<pre><?php print_r($custom_fields); ?></pre>

Code to the bottom of my invoice, and I can see the fields are populated, but how to add them to my invoice is not clear at all (the wiki text and screenshot are not aligned so I wonder if it’s still not updated for 1.5.0?)

 [client] => Array
 (
   [Company Number] => XXX
   [Contact] => TEST
   [Invoice Terms] => 14
   [Purchase Order Number] => TEST
 )

The following error (quite understandably) is logged for each custom field in my templates;

ERROR - 2017-04-24 08:57:38 --> Severity: Notice --> Undefined property: stdClass::$client_custom_contact /xxx/xxx/invoices/application/views/invoice_templates/pdf/xxx-default.php 69

Sorry for that, the wiki needs o many updates that I could work on it for the next 2 weeks.

So, the $custom_fields variable is a collection of all available custom fields where the index is the label of the field and the value the actual value. To output a field in your template, use something like that:

<?php echo $custom_fields['client']['Contact']; ?>

In your case, this should output TEST.

Another example:

<?php echo $custom_fields['client']['Invoice Terms']; ?>

would output 14.

3 Likes

That’s superb, thank you.

Has anything changed with the PDF engine? I’ve updated the custom fields so I no longer get PHP errors but my footer is now floating at the top of the page, in 1.4.10 (and all versions prior) the footer stuck nicely to the bottom of the page.

<p class="footer">Some Text At The Bottom</p>

The following does’t work either;

<div class="footer">Some Text At The Bottom</div>

EDIT2: Sorted it;

<div id="footer">Some Text At The Bottom</div>

The above forces the mpdf engine to pick up the relevant footer content.

I updated the wiki for the custom fields. https://wiki.invoiceplane.com/en/1.5/templates/customize-templates#custom-fields

About the footer: it works without problems for me. Did you added some special CSS for the footer? If I specify the footer in the settings the content is displayed at the bottom of each page, no floating.