Drupal · 7 min read · Updated

Drupal 11 Webform Tutorial: Build a Quote Form with Conditional Fields, Emails and Spam Protection

A tested Drupal 11 Webform tutorial: build a request-a-quote form with conditional fields, email handlers, Honeypot and CSV export.

Drupal 11 webform

Drupal core’s Contact module gives you one fixed form: name, email, subject, message. The moment you need a phone field, a dropdown, a field that only appears when a box is ticked, a copy of the submission for the visitor, or a CSV of everything people sent, you need the Webform module.

Webform is one of the most used contributed modules in Drupal, and version 6.3 runs on Drupal 11. In this tutorial we build a real “Request a quote” form on a fresh Drupal 11.4 site: conditional fields, server-side validation, two email handlers, spam protection and a CSV export. Every step was tested, and the output shown is what we got.

What we used

  • Drupal 11.4.14 on PHP 8.5, installed from the official drupal:11-apache Docker image
  • Webform 6.3.1, Honeypot 2.2.2 and Drush 13.8, all installed with Composer

If you can’t use Composer on your hosting, see our guide to running Drupal 11 without the command line.

Step 1: Install Webform with Composer

From your project root, the folder with composer.json, run:

composer require drupal/webform
vendor/bin/drush en webform webform_ui -y

Composer picked ^6.3 for Webform. Drush confirmed:

 [success] Module webform has been installed. (Permissions - Configure)
 [success] Module webform_ui has been installed.

Webform UI is the drag-and-drop builder. Keep it enabled while you build forms. You can turn it off on production later, and the forms keep working.

Without Drush, go to Extend, tick Webform and Webform UI, and click Install.

Step 2: Create the form

  1. Go to Structure > Webforms and click + Add webform.
  2. Enter the title Request a quote and check the machine name under it. We used quote_request. Click Save.
  3. On the Build tab, click + Add element and add each field. Pick the element type, give it a title and key, tick Required where needed, and save.

We added these elements:

TitleKeyTypeRequired
Your namenameText fieldYes
EmailemailEmailYes
PhonephoneTelephoneNo
I am ordering for a businessbusinessCheckboxNo
Company namecompanyText fieldOnly when the box is ticked
What do you need?serviceSelectYes
BudgetbudgetRadiosNo
Project detailsmessageTextareaYes
Drupal 11 Webform Build tab for Request a quote listing the elements Your name, Email, Phone, I am ordering for a business, Company name with the conditional Visible and Required, What do you need, Budget, Project details and Submit buttons
The finished element list. The Conditional column shows that Company name is Visible and Required only in some cases.

Faster: paste the YAML

Every webform is stored as YAML, and the Build > Source tab lets you edit it directly. This is the exact source of our form. Paste it into a new form’s Source tab to get the same fields in seconds:

name:
  '#type': textfield
  '#title': 'Your name'
  '#required': true
email:
  '#type': email
  '#title': Email
  '#required': true
phone:
  '#type': tel
  '#title': Phone
business:
  '#type': checkbox
  '#title': 'I am ordering for a business'
company:
  '#type': textfield
  '#title': 'Company name'
  '#states':
    visible:
      ':input[name="business"]':
        checked: true
    required:
      ':input[name="business"]':
        checked: true
service:
  '#type': select
  '#title': 'What do you need?'
  '#options':
    store: 'New online store'
    redesign: 'Store redesign'
    extension: 'Custom extension'
    support: 'Support and maintenance'
  '#empty_option': '- Select -'
  '#required': true
budget:
  '#type': radios
  '#title': Budget
  '#options':
    small: 'Under $1,000'
    medium: '$1,000 to $5,000'
    large: 'Over $5,000'
message:
  '#type': textarea
  '#title': 'Project details'
  '#required': true
actions:
  '#type': webform_actions
  '#title': 'Submit button(s)'
  '#submit__label': 'Request a quote'

The actions element at the end renames the submit button to “Request a quote”.

Step 3: Show the company field only for businesses

  1. On the Build tab, click Edit next to Company name.
  2. Open the Conditions tab.
  3. Set the state to Visible, if All of the following is met: I am ordering for a business [Checkbox], Checked.
  4. Click Add another state and add the same condition with the state Required.
  5. Save.
Edit Company name element in Drupal Webform on the Conditions tab with two states, Visible and Required, both when I am ordering for a business is Checked, and Clear values when hidden ticked
Two states on the same condition: visible and required only when the box is ticked.

Leave Clear value(s) when hidden ticked, which is the default. Webform also warns you that “when an element is hidden it will not be required”, which is exactly what we want: personal customers never see the company field.

We tested that the rule isn’t only cosmetic. With the box ticked, we removed the browser’s required attributes and submitted without a company name. Drupal still refused it on the server with “Company name field is required.” and saved nothing.

Request a quote form on the Drupal 11 front end with the business checkbox ticked and the Company name field visible and filled in as Lopez Coffee Co.
Tick the box and the Company name field appears.

Step 4: Set the confirmation message

Go to Settings > Confirmation, choose Message as the confirmation type and write the text. Tokens work here, so you can greet the visitor by name:

Thanks, [webform_submission:values:name]! We received your request and will reply within one business day.
Drupal 11 status message after submitting the form: Thanks, Maya Lopez! We received your request and will reply within one business day.
The confirmation after a real submission.

Step 5: Email yourself and the visitor

Go to Settings > Emails / Handlers. We added two Email handlers:

  • Email notification to you. To: [site:mail], the site email from Configuration > Basic site settings. Reply-to: [webform_submission:values:email:raw], so pressing Reply in your mail app answers the visitor directly. Subject: New quote request from [webform_submission:values:name].
  • Email confirmation to the visitor. To: [webform_submission:values:email:raw]. Subject: “We received your quote request”. The body includes [webform_submission:values], which prints every answer.
Drupal Webform Emails and Handlers tab listing an Email notification handler and an Email confirmation handler, both enabled
Two email handlers on the form.

To test email without sending real mail, we switched Drupal to core’s test mail collector with drush config:set system.mail interface.default test_mail_collector -y and read the messages back. After one submission there were two emails:

site@example.com | reply-to: maya.lopez@example.com | New quote request from Maya Lopez
maya.lopez@example.com | reply-to: Webo Drupal Lab <site@example.com> | We received your quote request

The default body lists every field by title, so you can read the whole request in your inbox. On a live site, install an SMTP module or use your host’s mail service so these emails don’t land in spam. Don’t forget to switch the mail system back from the test collector.

Step 6: Stop spam with Honeypot

A public form gets bot submissions within days. Webform integrates with the Honeypot module, which adds a hidden field that bots fill in and humans don’t, plus a minimum time before the form can be sent.

composer require drupal/honeypot
vendor/bin/drush en honeypot -y

Then open the webform’s Settings > General tab, expand Third party settings > Honeypot, and tick both boxes.

Webform Honeypot settings with Protect Request a quote webform with Honeypot and Add time restriction to Request a quote webform both ticked
Honeypot protection for this one form.

We tested it like a bot would:

  • Filling in the hidden field, which is named url, was rejected with “There was a problem with your form submission. Please refresh the page and try again.”
  • Submitting in under 5 seconds was rejected with “Please wait 11 seconds and try again.”
  • A normal visitor who took 6 seconds got the confirmation message, once we had cleared the failures from the earlier bot tests (more on that below).

Notice the 11 seconds. The default limit is 5 seconds, but Honeypot adds time for each failed attempt from the same IP address: the wait is the time limit plus e to the power of the number of failures, minus 1, capped at 300 seconds. In our test the wait went from 11 to 24 to 58 seconds. That stops bots that retry fast, but it also means you can lock yourself out while testing from one IP. Failures are stored in the honeypot_user table and expire on their own.

Step 7: View and export submissions

Every submission is stored in Drupal. Open the form’s Results tab to see them, open one to read it, or add notes.

Drupal Webform Results tab for Request a quote listing two submissions with serial numbers, dates and submitter details
Two test submissions on the Results tab.

Click Download on the Results tab to export a CSV or Excel file. With Drush you can script it, for example for a nightly export:

vendor/bin/drush webform:export quote_request --exporter=delimited --delimiter=, --destination=/tmp/quote-requests.csv
>  [notice] Exported 2 of 2 submissions…
Created /tmp/quote-requests.csv

The CSV starts with the submission details, such as serial number, dates and remote IP address, followed by one column per element, using the element titles as headers. Use your form’s machine name, which is also in its admin URL.

Things to watch for

  • Set up the private file system before adding file uploads. Set a private files path in settings.php first. Uploaded files are personal data, so they shouldn’t sit in the public files folder.
  • Personal data and retention. Webform stored the visitor’s IP address with each submission in our test, as the CSV shows. Review Settings > Submissions for the options to stop tracking IP addresses and to purge old submissions.
  • Don’t run Drush as root on a SQLite site. On our test container, installing the site as root left the database owned by root, and Apache failed with “attempt to write a readonly database”. Running Drush as the web server user fixed it.

Please let us know if you have any questions or suggestions, and subscribe to our YouTube channel for more video tutorials. You can also find us on Twitter and Facebook.

Filed underDrupal
Rupak Nepali
Written byRupak Nepali

Rupak Nepali is a web developer, manage Webocreation website and the author of six books:
Getting Started with OpenCart Module Development (Packt, 2013),
OpenCart Theme and Module Development (Packt, 2015),
OpenCart 4: Dev Guide for Themes & Extensions (2024),
OpenCart 4: User Manual (2025),
Cloudflare for the Enterprise Website (2026) and
The Technical Web Guide for Marketers (2026).
Rupak has built OpenCart stores and extensions since 2010, has published more than 600 tutorials on Webocreation, and shares free OpenCart extensions on GitHub.
Find Rupak on
GitHub | Amazon | LinkedIn | X | YouTube.

Leave a Reply

Your email address will not be published. Required fields are marked *