There is no best practice, I guess. I’d check if page creation was successful (so not already when form is submitted), then send an email. Example of sending email after form submission: Email contact form | Kirby CMS
This outputs the person that needs to be contacted. The person can vary (for example one person is having vacation, than another one is contact person, sometimes there can be multiple persons).
In e-mail form controller i got this line:
...
$kirby->email([
'template' => 'email.html',
'from' => 'no-reply@test.net',
'replyTo' => $data['email'],
'to' => ' HOW TO FETCH MAIL TO HERE ',
'subject' => esc($data['name']) . ' - Online-Beratungsanfrage für ' . $page->date()->toDate('%d %B %Y'),
'data' => [
'date' => $page->date()->toDate('%d %B %Y'),
'text' => esc($data['text']),
'sender' => esc($data['name'])
]
...
As you see, I’d like to transform one or multiple mails from template into controller into 'to' => '...', unfortunately I don’t have knowledge how to push it there to controller
You can’t push this information from the template to the controller. But why don’t you simply use the same code as in the template, or rather, extract the data from the same source into an array.