Repeating input fields in email contact form

I’m trying to create a simple order form based on the “Email contact form“ from the Kirby cookbook. The simple input fields already work. But I can’t get further with repeating input fields for the products.

Here a code snippet from my template:

<?php if($images = $page->images()->sortBy('sort','asc')):?>
<div class="products">

  <?php foreach ($images as $image): ?>
  <figure class="products__item product">
    <img class="product__image" src="<?= $image->crop(400, 400)->url() ?>" alt="<?= $image->title() ?>"></a>
    <figcaption class="product__caption">
      <div class="product__field">
        <input type="text" id="<?= $image->name() ?>" name="<?= $image->name() ?>" placeholder="–" value="<?= $data['what to insert here?'] ?? '' ?>">
        <label for="<?= $image->name() ?>">Stück</label>
  <?php endforeach ?>
<?php endif ?>

And a snippet from the controller:

if($kirby->request()->is('POST') && get('submit')) {


  $data = [
    // what to insert here? //
    'forename'  => get('forename'),
    'name'  => get('name'),
    'email' => get('email'),
    'street' => get('street'),
    'city' => get('city'),
    'phone'  => get('phone'),
    'notes'  => get('notes')


  if($invalid = invalid($data, $rules, $messages)) {
    $alert = $invalid;

  } else {
    try {

        'template' => '…',
        'from'     => '…',
        'replyTo'  => '…',
        'to'       => $data['email'],
        'subject'  => '…',
        'data'     => [
          // what to insert here? //
          'orderer'  => esc($data['forename']) . esc($data['name']),
          'phone'    => esc($data['phone']),
          'email'    => esc($data['email']),
          'street'   => esc($data['street']),
          'city'     => esc($data['city']),
          'notes'    => esc($data['notes'])

I hope I could make it clear.

Did you ever find a solution to that?

No, unfortunately not. I got around the problem in some way. But if there’s a solution, I would still be interested in it.

@renestalder Could you please explain your exact problem?

Never tried it in Kirby, but PHP accepts formats like this:

<form method="post">
   <!-- stuff -->
   <input name="pieces[itemname1]" value="0" />
   <!-- stuff -->
   <input name="pieces[itemname2]" value="0" />
   <!-- stuff -->

in PHP you then get:


/* writes something like:
array(2) {

Maybe the same works with the Kirby API

@texnixe Never mind. Now that I look at the solution of @rasteiner I realize, I’m looking for a solution to a different problem (validation of repeating fields e.g. password repeat) and will therefore check again if there is another thread that is more fitting.