Skip to main content
CalcBuilder logo

CalcBuilder Tutorial

Calc Builder field type: Linked List

A Linked List is a drop-down whose options depend on what the visitor picked in a parent drop-down — pick a Country and the City list only offers that country’s cities. The options are typed in by hand (Multiple Values); if they live in a database table, use the Linked List SQL type instead.

Country and City: the City list only shows French cities
The finished example: France is selected, so City only offers Paris, Lyon and Marseille.

How the link works (read this first)

There is no “depends on” setting for a Linked List. The link is made by two naming rules:

Parent field (Option List)Child field (Linked List)
Variablecountrycountry_city — the parent’s variable + _ + any word
Option values
(“Saved in database” column)
ES, FR, ITES_MAD, ES_BCN, FR_PAR, FR_LYS… — the parent option’s value + _ + any code
  1. Which field is the parent? Calc Builder takes the Linked List’s variable name and drops the part after the last underscore: country_city → country. That must be the variable of the parent field. (Parent variables may contain underscores themselves: ship_country → child ship_country_city.)
  2. Which options are shown? Same trick on each child option’s value: FR_LYS → FR. The option is shown only while the parent option whose value is exactly FR is selected. Matching is exact and case-sensitive.

If the child list is always empty, one of the two rules is broken: the variable prefix doesn’t match the parent’s variable, or the option values don’t start with a parent option’s value followed by _. The SQL query and Trigger field boxes you also see on the Advanced tab are not used by a Linked List — leave them empty (they belong to Linked List SQL).

Example: Country → City

1. The parent field. On Form Fields add a field Country, Variable country, Type Option List. On its Advanced tab add the options — left box “Show in user interface”, right box “Saved in database”:

Country options: Spain/ES, France/FR, Italy/IT

2. The child field. Add a field City with Variable country_city and Type Linked List:

City field: variable country_city, type Linked List

3. The child options. On the City field’s Advanced tab add every city of every country, each value prefixed with its country’s value:

City options: Madrid/ES_MAD, Barcelona/ES_BCN ... Naples/IT_NAP

4. Form Layout. Place both fields as usual:

<div class="row g-3" style="max-width:520px">
  <div class="col-6"><label class="form-label fw-bold">Country</label>##country##</div>
  <div class="col-6"><label class="form-label fw-bold">City</label>##country_city##</div>
  <div class="col-12 mt-4"></div>
</div>

5. PHP code. Each list gives you two variables: the value of the chosen option and, with the _name suffix, its label:

VariableExample
$country"FR"
$country_name"France"
$country_city"FR_LYS"
$country_city_name"Lyon"
// $country       -> value of the chosen country, e.g. "ES"
// $country_name  -> its label, e.g. "Spain"
// $country_city  -> value of the chosen city, e.g. "ES_MAD"
// $country_city_name -> its label, e.g. "Madrid"
$city_code = substr($country_city, strlen($country) + 1);   // "MAD"

$shipping_rates = ['ES' => 4.95, 'FR' => 7.50, 'IT' => 8.90];
$shipping = number_format($shipping_rates[$country] ?? 0, 2);

6. Exit Layout. The same variables work as ##placeholders##:

<div class="p-3 border rounded" style="max-width:520px">
  <div class="d-flex justify-content-between mb-2"><span>Delivery to</span><strong>##country_city_name##, ##country_name##</strong></div>
  <div class="d-flex justify-content-between mb-2"><span>City code</span><strong>##city_code##</strong></div>
  <hr>
  <div class="d-flex justify-content-between"><span>Shipping cost</span><strong style="font-size:1.3rem">##shipping## &euro;</strong></div>
</div>

Result

On page load the City list already contains the cities of the default country (Spain). Changing the country refills it straight away in the browser — no round trip to the server — and the first city of the new country is selected.

Result: Lyon, France, city code LYS, shipping 7.50 EUR

Part of the Form Fields reference. Need the options from a database table instead? See Linked List SQL.

...
CalcBuilder

Create dynamic calculators

Buy now!
...
IA Calculators

Let our AI assistant generate your CalcBuilder calculators (pack of 5 calculators)

Buy now!