blog-banner

Displaying Webform Submission Data in Drupal Views

  • Drupal 7
  • Drupal Planet
  • Views
  • Web Form

Drupal Webform Views

 

Although the Webform module comes with limited integration to expose the submitted data in Views, it lacks the fine control to make View by Webform fields as rows and columns. There is a workaround to achieve this though which I would like to briefly run through in this blog.

Webform MySQL Views together with Data and Schema modules with a patch to Webform MySQL Views from issue #889306: Allow the designation of a primary key for MySQL views makes this feasible.

Webform MySQL Views, as the name implies, allows us to create MySQL views from Drupal, leveraging the Data module which counts on the Schema module.

The data module wraps a bundle of sub-modules, among them, Data Search provides Views Integration and Data Admin UI for accessing its administrative pages.

Once the mentioned modules are enabled. You can see a sub-menu "MySQL Views" under Administration » Content » Webforms. Tick the Webform node whose fields are needed in Views. This form is only meant to create a MySQL views.

Now the next step is to make the Data module adopt this view so it would be recognized by the Views module. For the same open the admin page at Administration » Structure » Data tables (or /admin/structure/data/adopt). Select the view from the "Orphaned Tables" list and hit the "Adopt" button.

 

Now apply the patch from #889306: Allow the designation of a primary key for MySQL views. This can be added to any of your custom modules. You will have to change the {yourcustommodule}_views_data_alter(&$views) hook implementation to match your module's code.

Typically $dbview_name would be webform_views_mywebform (depends on webform name) and $pseudo_pk would be sid. You will have to repeat this depending on the no of Webform nodes to be made available to use with Views.

Clear cache so that your new hook implementation would be known to Drupal core and Data shall be able to let use our webform node view as a base table for Views.

Now create a new Drupal View, needless to say, still from Administration » Structure » Views » Add new view. Under show, you should be able to see a new base table adopted by Data.

Now you could see separate Fields, Filter, and Sort criteria available per field in Webform.

In case, you find that a field is not properly handled by View, you can change the handler(s) from Administration » Structure » Data tables » Data table. In my case, the DateTime field was not properly handled by default, I had to change the handlers to fix the same.

Would like to see Webform comes up with a native solution to achieve this in upcoming releases. Have a thought or question? Post it in the comment below to discuss.

Get awesome tech content in your inbox