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 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-apacheDocker 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
- Go to Structure > Webforms and click + Add webform.
- Enter the title Request a quote and check the machine name under it. We used
quote_request. Click Save. - 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:
| Title | Key | Type | Required |
|---|---|---|---|
| Your name | name | Text field | Yes |
| Yes | |||
| Phone | phone | Telephone | No |
| I am ordering for a business | business | Checkbox | No |
| Company name | company | Text field | Only when the box is ticked |
| What do you need? | service | Select | Yes |
| Budget | budget | Radios | No |
| Project details | message | Textarea | Yes |

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
- On the Build tab, click Edit next to Company name.
- Open the Conditions tab.
- Set the state to Visible, if All of the following is met: I am ordering for a business [Checkbox], Checked.
- Click Add another state and add the same condition with the state Required.
- Save.

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.

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.

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.

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.

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.

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.phpfirst. 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.
Related posts
- Upgrade Drupal 10 to Drupal 11
- Drupal recipes
- Drupal Canvas page builder
- Cloudflare rules for Drupal
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.







