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>
</div>
</figcaption>
</figure>
<?php endforeach ?>
</div>
<?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 {
$kirby->email([
'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.