The Drupal Webform module is a small form builder that drifts into being a CRM after two years — every department adds a handler, file uploads pile up in the private directory, and nobody can answer “where do the submissions go.” This article is the operator’s mental model: how the element library, submission handlers, and access checks fit together, what to enable for anti-spam, how exports and mail routing actually behave under load, and which submodules to leave off. It applies to Webform 6.x on Drupal 10.
How to verify
Quick state check on a site you’ve inherited:
cd /var/www/drupal
drush pm:list --type=module --status=enabled | grep -i webform
# webform Webform Enabled 6.2.x
# webform_ui Webform UI Enabled 6.2.x
drush sqlq "SELECT COUNT(*) FROM webform_submission;"
# 184213
drush sqlq "SELECT webform_id, COUNT(*) c FROM webform_submission \
GROUP BY webform_id ORDER BY c DESC LIMIT 5;"
drush config:get webform.settings purge | head -20
# (look for purge_days; if missing, submissions live forever)
drush ev "print_r(\Drupal::service('webform.spam_protection_manager')->getEnabledProtectors());"
# at least: honeypot, time_restriction, captcha if installed
If webform_submission has more than 50k rows on a small site, you are storing things you don’t read. Decide what to keep, then enable purge.
What’s happening
Webform stores three things: the form definition (a YAML blob inside a config entity), the submissions (rows in webform_submission plus per-field rows in webform_submission_data), and the handlers attached to each form (email, remote post, custom). Every submit walks the handler chain in order; a Stop processing exception in one handler short-circuits the rest. The schema is intentionally generic — fields are not promoted to columns — so the database grows linearly with submissions times fields, and reports are slower than people expect.
The element library is just an alter chain over Drupal’s Form API. Each element has a render array plus webform-specific keys (#webform_key, #prepopulate, #multiple). The settings UI writes YAML that Webform parses on render; that YAML is what gets exported with drush config:export if you store webforms as config. By default, webforms are content entities (live in the database, change without a deploy). You can promote them to config — useful when the form is part of the product, not part of the editorial workflow — but you commit to redeploying for every label change.
Submission handlers run server-side after validation. The built-in email handler queues a mail through Drupal’s mail system, which by default uses PHP mail() — fine for a dev VM, never for production. Real installations send mail through SMTP (the smtp contrib module) or, better, a transactional API (Symfony Mailer + Mailgun/Postmark transport). Webform also ships a Remote Post handler that does an HTTP POST to any URL — that’s how Webform talks to Salesforce, HubSpot, or your own service bus. Treat it as a webhook: timeouts, retries, signature verification are your job.
The procedure
-
Pick storage strategy per form. Forms with high churn (campaign landing pages) stay as content. Forms that ship with the codebase (contact, support intake) go into config: edit the form, then
drush wfp:export contact > config/sync/webform.webform.contact.yml. Decide once, document it. -
Wire mail through SMTP, not PHP
mail(). Installsymfony_mailerand a transport:composer require drupal/symfony_mailer drush en symfony_mailer -y drush config:set symfony_mailer.settings default_transport smtpConfigure the SMTP transport with credentials stored outside Git (use Key module + State, or the secrets store you already run).
-
Enable anti-spam. Three layers, cheapest first:
- Honeypot (built into Webform settings, no UI for the user).
- Time restriction (reject submissions faster than 4 seconds).
- CAPTCHA + reCAPTCHA v3 or hCaptcha only on high-value forms.
drush config:set webform.settings third_party_settings.honeypot.honeypot true drush config:set webform.settings third_party_settings.honeypot.time_restriction 4 -
Turn on submission purging. Per form, in the Settings tab, set “Submission purge” to “All” (or “Draft only” if you keep finals forever) with a number of days that matches your retention policy. Then run
drush crondaily — purging is a cron task, it does not happen on submit. -
Quarantine file uploads. Webform file fields default to
public://webform/<webform_id>/. Change them to private, then audit:drush sqlq "SELECT uri FROM file_managed WHERE uri LIKE 'public://webform%';" # if any rows: those files are world-readable via the webserverMove private files out of
/var/www/drupal/web/entirely ($settings['file_private_path'] = '/var/www/drupal/private';) and exclude that directory from your release artifact. -
Add a Remote Post handler with retries. The built-in one fires-and-forgets. For Salesforce/HubSpot integrations, wrap it in a queue:
// In a custom module, react to WebformSubmissionEvent::SUBMITTED $queue = \Drupal::service('queue')->get('webform_remote_post_retry'); $queue->createItem([ 'webform_id' => $submission->getWebform()->id(), 'sid' => $submission->id(), 'attempts' => 0, ]);A QueueWorker plugin processes the item, posts to the endpoint, and re-queues on 5xx with exponential backoff. Capped at five attempts, then alerts.
-
Export submissions on a schedule. For audit and reporting:
drush webform:export contact \ --destination=/var/backups/webform/contact-$(date +%F).csv \ --range-type=date --range-latest=1 --header-format=labelCron this nightly. CSVs land on the backup volume, not the web tree.
Common pitfalls
- The Webform UI submodule (
webform_ui) lets editors add elements through the admin — convenient on staging, dangerous in production. Disable it on prod and force changes through config. - Email handlers queue through
MailManagersynchronously — a slow SMTP relay makes the submit button hang for the user. Use Symfony Mailer’s queue transport or a real async pipeline. - Submission YAML caches aggressively; after a config import, run
drush cror editors see the old form labels. - The
webform_submission_datatable grows by fields × submissions — a 30-field form with 50k submissions is 1.5M rows, and reports paginate slowly above that. - Webform’s “Lock submission” toggle stops edits but not deletions — if your retention policy depends on locking, also restrict the delete permission.
For sites where the contact form is the lead funnel, Stack Harbor runs Webform as a tracked component — handler chain audited, mail transport monitored, purge cron alerted, exports landing on the backup volume — so the marketing team can iterate on copy without breaking the integration. That’s the operating model under managed operations; related notes live in the knowledge base.