Project
Pick your team: a Gravity Forms plugin, rebuilt
A form where each dropdown fills in from the one before it: league, then season, then team. It’s my rebuild of a WordPress plugin I maintained, which turned CSVs uploaded in wp-admin into linked Gravity Forms fields.
- My role
- Maintained the original · solo rebuild
- Stack
- wordpress
- gravity forms
- acf pro
- php
- jquery
- react
- typescript
Why I built it
I maintained this plugin for a client in the auto industry. Along with keeping it running, I wrote the docs that showed the client how to upload their CSVs, added new model years, set up conditional logic so fields showed or hid based on earlier answers, mapped the form values into their support ticketing system, and made sure each email reached the right person.
The original belongs to the client, so I rebuilt the idea here to have a version I can show. The client’s dropdowns were vehicles: year, make, model and type. This one uses women’s pro sports leagues instead.
Pick a league, then a season, then a team. Open Show the data behind it to see the CSV and what the code turns it into.
How the WordPress version works
Explain it like I’m five
The CSV is a family tree. The first dropdown asks which branch you want, the next one only shows that branch’s children, and so on down. Change your mind near the top, and everything below it resets.
From spreadsheet to form
- CSV uploadACF options page
- PHP reads itCached for a day
- Custom fieldsAdded in the form editor
- jQueryFills the next dropdown
- Uploading the data. An ACF Pro options page in wp-admin has a repeater with one row per model year: the year and a CSV file. A new model year was a content edit, not a code change.
- Reading it. PHP parses each CSV, turns it into JSON and caches it as a transient for a day. Saving the options page clears the cache, so a new upload shows up right away.
- The fields. The plugin registers four custom Gravity Forms field types (Year, Make, Model and Type) by extending
GF_Field. They show up under Advanced Fields in the form editor, so they can go on any form. - Filling the dropdowns. The JSON is printed into the page, and a jQuery script listens for changes and rebuilds the options in the next dropdown.
What I changed in the rebuild
One row per team
The original CSV had one row per make. All the models went in a single cell with line breaks between them, and the types for each model went in the next cell, lined up by line number. In this demo’s terms, it looked something like this:
League,Season,Teams
PWHL,"2024–25
2025–26","Boston Fleet,Minnesota Frost,Montréal Victoire,…
Boston Fleet,Minnesota Frost,…,Seattle Torrent,Vancouver Goldeneyes"The rebuild uses one row per team. It’s longer, but every row stands on its own, and it’s the shape most spreadsheet exports already have.
League,Season,Team
PWHL,2024–25,Boston Fleet
PWHL,2024–25,Minnesota Frost
PWHL,2025–26,Seattle TorrentLine 3 has to match line 3
When values are lined up by position across two cells, adding one in the middle of one cell and forgetting the other shifts everything below it. Nothing errors. The form just quietly offers the wrong choices for every row after that line.
Build the tree once
The original printed each year as its own global variable (json_2016, json_2017…), found the right one with eval('json_' + year), and walked the raw rows again on every change. The rebuild reads the CSV once into a tree (league → season → teams), so each dropdown is just a lookup.
function buildTree(rows: string[][]): Tree {
const tree: Tree = new Map()
for (const [league, season, team] of rows.slice(1)) {
if (!league || !season || !team) continue
const seasons = tree.get(league) ?? new Map<string, string[]>()
const teams = seasons.get(season) ?? []
if (!teams.includes(team)) teams.push(team)
seasons.set(season, teams)
tree.set(league, seasons)
}
return tree
}Back in WordPress, the same fix is to hand the script one object with wp_add_inline_script() instead of printing a separate variable for each year.
Options are text, not HTML
The original built each option by gluing strings into HTML. That works until a value contains a < or a &, and then the browser reads it as markup. An editor uploads the CSV, so this is more about broken forms than attacks, but it’s the same habit that prevents XSS: treat data as text. The rebuild creates real elements, and the same fix works in jQuery:
// Before: the value becomes HTML
html += '<option value="' + team + '">' + team + '</option>'
// After: the value stays text
$('<option>').val(team).text(team).appendTo($select)Easier to use without a mouse
Season and Team stay disabled until the dropdown before them has a value, and their placeholder says why (“Pick a league first”). After each pick, a status line tells screen reader users how many choices the next dropdown has.
Not on Gravity Forms?
The same pattern works with Contact Form 7 or any other form plugin. The CSV and the tree stay the same; only the part that registers the fields changes.