I'm using CiviCRM 4.6 with Drupal 7 and have added the Supplemental Address Field 1 in CiviCRM but I can figure out how to get it to show in my custom BillingBlock.tpl


You have created a new template or customized one, right? Do you already have the address data available in your template? You can check this by making sure debugging is switched on in your environment and then access your BillingBlock.tpl but add &smartyDebug=1 at the end of the url. If not, you can use the API to retrieve the address data, assuming you know the contact id. In Smarty you can do:

{crmAPI var='result' entity='Address' action='get' q='civicrm/ajax/rest'}
{foreach from=$result.values item=Address}

This will allow you to retrieve the supplemental address.

  • I am using a custom BillingBlock.tpl, except it is from version 4.5 - I like the way this template spits each field out individually as it's easier for a civi novice like me to customise.
    – jptaranto
    Aug 5 '15 at 0:03
  • Anyway I've run smartydebug and there is no supplemental address field inside the $billingDetailsFields array. With the code you added pasted into the tpl I was able to get some values of the supplemental address field to print out using the id of supplemental_address_1.
    – jptaranto
    Aug 5 '15 at 0:03
  • I'm still not sure how to print the field in the template so users can enter their information into the form. The other billing fields are printed as so: {assign var=n value=billing_street_address-$bltID} <div class="crm-section {$form.$n.name}-section"> <div class="label">{$form.$n.label} {$reqMark}</div> <div class="content">{$form.$n.html}</div> <div class="clear"></div> </div>
    – jptaranto
    Aug 5 '15 at 0:03
  • Your question was how to show, not how to enter data? So my answer tells you how to show the field. Entering data is a different ballgame. You will need to use CiviCRM hooks to do that, (PHP customization). In a template you can create an input field but you also need to save the data. Do you want to get into the details of this customization? Aug 5 '15 at 7:09
  • Sorry, I should have worded it differently. I realise it is probably pretty tricky but it would be great if you could provide some examples. I'm sure it would be pretty handy to a few people.
    – jptaranto
    Aug 5 '15 at 22:20

If you want to add an input field it is important first to establish if this is a form (where stuff can be edited like edit a contact) or a page (showing stuff like the contact summary). I assume you are referring to a form where you can already edit stuff.

There are several ways in which you could put a new input field on a form, this is what I tend to do:

Create a new extension (or use an existing one) with civix as documented here : http://wiki.civicrm.org/confluence/display/CRMDOC/Create+a+Module+Extension

Then create a template for the field(s) and include some jQuery that moves the to the appropriate spot, like so:

<div id="maf-earmarking" class="crm-summary-row">
  <div class="crm-label">{$form.earmarking.label}</div>
  <div class="crm-content crm-recurring-earmarking">{$form.earmarking.html}   
  <script type='text/javascript'>

Finally add the element to the form using the buildForm hook in .php like so:

$earMarkings = array(0 => ts('- select -')) + _recurring_getOptionList('earmarking');
$form->add('select', 'earmarking', ts('Øremerking'), $earMarkings, true);

In this example a select box is added, if you want to add an input fields, use $form->add('text'....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.