Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Webform Query

No security coverage Under active development 547 sites

Part of the Webform ecosystem · 217 projects

This module helps you extract specific webform submission data based on field values and criteria. You can query submissions from a particular webform, filter them by various conditions, and even sort the results. It also allows querying other tables that contain submission IDs and supports array-based queries for more flexible filtering.

Query Webform Submission Data

The Webform module stores all submission data in the one table using the EAV model. This is great for performance but it can be tricky to extract submission data matching certain criteria.

Webform Query extracts submission IDs based on field values. Currently it supports adding conditions and specifying the webform ID. For example, this would return all "event_registration" submissions for event 1 where the age is 18 or over:

$query = \Drupal::service('webform_query');

$query->addCondition('event', 1)
      ->addCondition('age', 18, '>=')
      ->setWebform('event_registration');
$results = $query->execute();

The return type is an array of objects with a single property "sid", the submission ID. The webform submissions can then be loaded in the normal way.

The webform_id is optional. This would return all webform submissions where the value of the "event" field is 1.

$query = \Drupal::service('webform_query');

$query->addCondition('event', 1);
$results = $query->execute();

Sort the results

$query = \Drupal::service('webform_query');

$query->addCondition('event', 1);
$query->orderBy('age', 'DESC');
$results = $query->execute();

"ASC" is used if the second parameter is missing. The third optional parameter is the table.

$query = \Drupal::service('webform_query');

$query->addCondition('event', 1);
$query->orderBy('created', 'DESC', 'webform_submission');
$results = $query->execute();

Query other tables

Querying other tables which include a sid column is now possible. This is useful for querying the webform_submission table to filter by user, date submitted and other base fields.

addCondition() accepts a table name as an optional fourth parameter.

These tables are queried before webform_submission_data to improve performance.

$query = \Drupal::service('webform_query');

$query->addCondition('event', 1)    
      ->setWebform('event_registration')
      ->addCondition('uid', 1, '=', 'webform_submission');
$results = $query->execute();

Array Queries (IN)

$query = \Drupal::service('webform_query');
$query->addCondition('event', 1)    
      ->setWebform('event_registration')
      ->addCondition('uid', [1, 5, 7], 'IN', 'webform_submission');
$results = $query->processQuery()->fetchCol();
$query = \Drupal::service('webform_query');
$query->addCondition('event', 1)    
      ->setWebform('event_registration')
      ->addCondition('age', [18, 19, 20], 'IN', 'webform_submission_data');
$results = $query->processQuery()->fetchCol();

Additional result types

The method processQuery() returns Drupal\Core\Database\Statement which allows for different result types.

$query = \Drupal::service('webform_query');

$query->addCondition('event', 1)    
      ->setWebform('event_registration')
      ->addCondition('uid', 1, '=', 'webform_submission');
$results = $query->processQuery()->fetchCol();

Ask your assistant about Webform Query

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Feb 2023
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Active

Releases

Version Type Core PHP Release date
8.x-1.0-alpha4 Pre-release 8–11 Jan 31, 2025
8.x-1.0-alpha3 Pre-release 8–10 Feb 16, 2023