Add a car make and model dropdown to WordPress
Where the picker goes in the block editor, and how to get the vehicle into Contact Form 7, WPForms or Gravity Forms submissions.
WordPress gives you two places to work with: the page itself, where the block editor takes HTML, and a form plugin, which decides what ends up in your inbox. The picker goes in the first one. Getting the chosen vehicle into the second one takes one extra step, and this guide walks through it for the three form plugins most WordPress sites use.
What you get
A make select, a model select that fills when someone picks a make, and a year select, from the official vehicle registers behind the VehiclesDB dataset. It covers cars by default; motorcycles, vans and trucks are an option. Your visitor picks Volkswagen, then the Golf, and you stop guessing what "vw golf 7 1.6" means.
The block
Paste where the vehicle fields go
<label for="vehicle-make">Make</label>
<select id="vehicle-make" name="make"></select>
<label for="vehicle-model">Model</label>
<select id="vehicle-model" name="model"></select>
<label for="vehicle-year">Year</label>
<select id="vehicle-year" name="year"></select>
<script src="https://cdn.jsdelivr.net/npm/make-model-dropdown@0.4.1"></script>
<script>
VehiclesDropdown.attach({
make: "#vehicle-make",
model: "#vehicle-model",
year: "#vehicle-year",
kind: "car",
order: "popular",
includeOther: true,
otherLabel: "Other / not listed",
placeholderMake: "Make",
placeholderModel: "Model",
placeholderYear: "Year",
source: "dataset"
})
</script>
This block works as it is, with no key and no account: it reads the open dataset and shows a small credit line under the picker, which free use requires. Paid plans can remove the credit line.
Want another language, vehicle kind or country? Choose your options and copy your own block. A free key adds make logos and puts the most registered makes at the top of the list.
Put the picker on a page
- Open the page or post in the block editor.
- Add a Custom HTML block: click the Block Inserter (the + button), or type
/htmlin a new paragraph and press Enter. - Paste the block into it. In recent WordPress versions you paste it through the block's Edit HTML button and confirm with Update.
- Save or update the page, then open it in a private window to see what a visitor sees.
One thing to know before you start: WordPress strips <script> tags from a Custom HTML block when the person saving it lacks the unfiltered_html capability (Authors and Contributors, for example). On a single site, Administrators and Editors have it. On a multisite network, only Super Admins do. If the picker vanishes after you save, that is why.
On WordPress.com, JavaScript needs a plugin-enabled plan with hosting features activated, according to WordPress.com's own documentation at the time of writing. On other plans the script is removed when you save.
Get the vehicle into your form
A Custom HTML block on its own is not a form, so nothing is sent anywhere. Where the answer goes depends on the form plugin. We checked each one's documentation for a way to put fields of your own inside its forms and have them saved. None of the three promises that:
- WPForms says its HTML field is not included in your form's entries.
- Gravity Forms says HTML fields are display only and not saved in the entry.
- Contact Form 7 accepts HTML in its form template, but its emails are built from its own mail-tags, one per form-tag, and its documentation doesn't say that a select it didn't create is sent.
What all three do have is a hidden field: a field the visitor never sees, sent with the form like any other. So the picker goes in a Custom HTML block right above the form, and a few lines of script copy the chosen vehicle into the form's hidden field whenever it changes.
Paste right after the picker block
<script>
document.addEventListener("make-model-dropdown:change", function (event) {
var field = document.getElementById("vehicle-choice")
if (!field) return
var picked = event.detail
field.value = [picked.make, picked.model, picked.year].filter(Boolean).join(" ")
field.dispatchEvent(new Event("change", { bubbles: true }))
})
</script>
Put the picker block and these lines in the same Custom HTML block (or two blocks, one after the other), above your form. Then set up the hidden field:
Contact Form 7. In the form's Form tab, add this form-tag anywhere inside the form: [hidden vehicle-choice id:vehicle-choice]. Then, in the Mail tab, put the mail-tag [vehicle-choice] in the message body where you want the vehicle to appear. Contact Form 7 doesn't add new fields to your mail by itself; the mail-tag is what puts it there.
WPForms. Add a Hidden Field to the form (WPForms lists it as a Basic license feature or higher). Publish the page, open it, right-click the form and choose Inspect to read the hidden field's id, and put that id in place of vehicle-choice in the lines above.
Gravity Forms. Add a Hidden field to the form. As with WPForms, read the field's id in your browser (right-click, Inspect) and put it in place of vehicle-choice.
If whoever built your site prefers to wire it differently, the picker announces every choice with a make-model-dropdown:change event; that's all the lines above listen to.
Check that it works
- Open the page in a private window, so you see it as a visitor does.
- Pick a make, a model and a year.
- Send the form to yourself, as a real customer would.
- Look for the vehicle in the email or in the plugin's entries. It arrives as short lowercase names, such as
volkswagen golf 2019.
The picker is done when that test submission arrives with the vehicle in it, not when the lists appear.
Common problems
- The picker is gone after saving. The page was saved by a user without
unfiltered_html, or the site is on a WordPress.com plan without JavaScript. See above. - The lists appear, but the vehicle is missing from the email. The hidden field's id and the id in the lines above don't match, or (Contact Form 7) the mail-tag is missing from the Mail tab.
- A plugin that delays or combines scripts. If the picker only appears after you scroll or click, exclude its script from that plugin.
-
Nothing loads, and the browser console mentions a Content Security Policy.
Your site sends a policy that blocks scripts from other sites. Allow
https://cdn.jsdelivr.netfor scripts and connections, andhttps://vehiclesdb.comfor connections if your block has a key. -
You use a block with a key.
A key only works on the websites it is locked to. Keys made on the
embed page are locked to your site and also work on your own computer
(
localhost) for testing. To test on a staging or preview address, add it to the key's websites in Settings first.
Built for you by an agency?
Send them this page. Agencies add the same picker to every client's booking form, and the booking forms guide explains what it does for garages, tyre shops and detailers. Guides for other site builders are on the make and model dropdown page.
Questions people ask
Do I need a plugin to add the make and model picker to WordPress?
No. The block editor's Custom HTML block is part of WordPress. You need a form plugin only if you want the vehicle to arrive in a form's emails or entries, and then the picker still goes in a Custom HTML block next to the form.
Why did the picker disappear after I saved the page?
WordPress removes script tags from Custom HTML blocks saved by a user without the unfiltered_html capability, such as an Author or a Contributor. On a single site, Administrators and Editors have it; on a multisite network, only Super Admins do. Ask one of them to paste the block.
Does it work on WordPress.com?
WordPress.com's documentation says JavaScript works on sites with a plugin-enabled plan and hosting features activated, and that free sites have limits on the code they can add. Without that, the picker's script is removed when you save.
What arrives in my email when someone picks a car?
The make, model and year as short lowercase names, such as volkswagen golf 2019, in whichever field you set up below.