Skip to main content

CalcBuilder Tutorial

Calc Builder 6: sections (repeatable groups of fields)

A section is a group of form fields that the visitor can repeat — “add another window”, “add another passenger”, “add another line”. In the PHP each field of a section becomes an array, one entry per repetition.

Sections screen

How it looks on the front end

A repeatable section on the front end
The demo Quote Builder: one section named line with an Item, Qty and Unit price field. Add line appends a row; each row has its own Del button. Default sections was set to 2 and Limit to 8.

Creating a section

  1. Open Sections and add a section with a Name.
  2. Set Default sections (how many rows show initially) and Limit (maximum, -1 for unlimited).
  3. Turn on Add button so the visitor can create more rows.
  4. Design the row with a layout using ##field## placeholders for the fields that belong to the section.

Using a section in code

Every field of the section arrives as an array — one entry per row the visitor added. Loop over them:

$rows = '';
$subtotal = 0;
for ($i = 0; $i < count($qb_item); $i++) {
    $line = (float) $qb_qty[$i] * (float) $qb_price[$i];
    $subtotal += $line;
    $rows .= '<tr><td>' . $qb_item[$i] . '</td>'
           . '<td class="text-end">' . number_format($line, 2) . '</td></tr>';
}
$vat   = $subtotal * 0.21;
$total = $subtotal + $vat;
$table = '<table><tbody>' . $rows . '</tbody></table>';

Then print ##table##, ##subtotal##, ##vat## and ##total## in the Exit Layout:

The quote result built from the section rows
Three lines in → a full quote out (Subtotal 1,289.00 €, VAT 21% 270.69 €, Total 1,559.69 €).

Placing the section in the form

In the Form Layout, put ##<section name>## where the repeating rows should appear — here ##line##. The fields that belong to the section must not also be placed individually.

For a choice field inside a section (Option List, Radiobutton…), $field[$i] is the option value and $field_name[$i] its label. Sections are what turn a flat calculator into a full quote builder, a multi-passenger fare or a bill-of-materials.

...
Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!
...
CalcBuilder

Create dynamic calculators

Buy now!