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.
43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?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);
|
|
}
|
|
} |