add form submission handling and confirmation emails

Validate form submissions and action configuration, execute finishers with submission context, and return JSON success or error responses. Add configurable confirmation emails to submitters and report failed submissions in the form UI.

Harden database and admin email finishers, and add submission handler and confirmation email checks.
This commit is contained in:
2026-11-24 11:26:37 +01:00
parent 80e60d6823
commit c507618b90
10 changed files with 593 additions and 47 deletions
@@ -0,0 +1,43 @@
<?php
namespace Plugi\Extensions\Form\Finishers;
class SendConfirmationEmailToSubmitter extends DefaultFinisher
{
public function execute(): bool
{
$recipientField = $this->options['recipientField'] ?? null;
if (!is_string($recipientField) || $recipientField === '') {
return false;
}
$emailFieldExists = false;
foreach ($this->getFormFields() as $field) {
if (($field['name'] ?? null) === $recipientField && ($field['type'] ?? null) === 'email') {
$emailFieldExists = true;
break;
}
}
if (!$emailFieldExists) {
return false;
}
$recipient = $this->getEntryFields()[$recipientField] ?? null;
if (!is_string($recipient) || filter_var($recipient, FILTER_VALIDATE_EMAIL) === false) {
return false;
}
$subject = $this->options['subject'] ?? null;
$message = $this->options['message'] ?? null;
if (!is_string($subject) || trim($subject) === '' || strpbrk($subject, "\r\n") !== false || !is_string($message) || trim($message) === '') {
return false;
}
return $this->sendMail($recipient, $subject, $message);
}
protected function sendMail(string $recipient, string $subject, string $message): bool
{
return mail($recipient, $subject, $message);
}
}