Jacob Rockowitz: Webform Composites vs. Tables

Collecting rich and structured data

In our API-first and data-driven world, we need to collect rich and structured data. The Webform module for Drupal 8 empowers websites to build any type of form which collects any type of data.

The Webform module supports composites elements, which are multiple inputs working together to collect rich and structured data. Composite elements can collect information, including addresses. Composite elements combined with the Webform module’s support for multiple values can collect multiple addresses that are represented using a table where rows can be added or removed. Yet, the Webform module’s support for composite elements has some limitations.

Composites the good and the bad

The best way to begin using and understanding composites is to build a webform that contains an address element and examine how the address element’s data is submitted, stored, and exported. Below is a quick demo of a basic address composite element. If you install and enable the Address module, you can add an ‘Advanced address’ element to your webforms, which does a great job of managing locality and zip codes.

If the default composite elements included in the Webform module do not meet your requirements, you can also create a custom composite in the Webform module’s UI or using custom code.

To create a custom composite, add a ‘Custom element’ to your webform, select the desired elements and voila, you have a custom composite.

An immediate limitation that site builders will notice is the not all webform elements are available via the UI. Also, elements that collect multiple values are not supported. The Webform module stores submission data using an Entity-Attribute-Value (EAV) model, which limits the complexity of what type of data can be collected….Read More