Getting a contact's data in to a block on a webform

The scenario here is, for example, you are calling your Contacts and recording data via webform using webform_civicrm, and you are using a View to get your list of contacts. On that View you have a link adds the Contact ID (cid) in the url so that person's name etc will load up on the webform.

In this case we also want to have some other information about them, such as their Donation History.

To achieve this we need to build a View Block using a Contextual filter that looks for the contact ID in the url (and doesn't show anything if we do not have a cid available)

But when you place that Block on the webform, the Block does not know to grab the cid from the url. 

So we need a small extension which tells that Views Block to find the contact ID in the url.

Here are the steps for adding the Contextual Filter to the View (in this case a CiviContact based View)

 

And you find the filter for Contact ID

And here are the settings to use

Then in the module we need to tell it the Views 'machine name' which you can find in the url when you are editing the view, it is the part highlighted in bold below

admin/structure/views/view/last_donation

So the code in the module looks like this and the bit you are swopping for your Views machine name is in bold

  case 'contributions_summary':
    $view->args[] = $_GET['cid1'];

Once you have set this up, you then find your Block and set it to show above your Webform content and if all steps have been followed, when you go to that webform with a url like this

/node/57?cid1=281

you will see their Donation History showing above the form

 

AttachmentSize
Package icon tidbits.zip780 bytes