Implement form validation and error handling for email sending in Register class
This commit is contained in:
@@ -15,10 +15,16 @@ class Register extends Renderer {
|
|||||||
protected string $templateName = 'renderer';
|
protected string $templateName = 'renderer';
|
||||||
|
|
||||||
protected function formAction(): void {
|
protected function formAction(): void {
|
||||||
|
if (!$this->formCheckFields()) {
|
||||||
|
// Bei Validierungsfehlern: nichts speichern, keine Mail, Fehler im Formular anzeigen
|
||||||
|
return;
|
||||||
|
}
|
||||||
$this->writeToDb();
|
$this->writeToDb();
|
||||||
$this->sendEmail();
|
$this->sendEmail();
|
||||||
|
if (count($this->errors) === 0) {
|
||||||
$this->templateName = 'register_successful';
|
$this->templateName = 'register_successful';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function formCheckFields(): bool {
|
protected function formCheckFields(): bool {
|
||||||
$username = trim(filter_input(INPUT_POST, 'username', FILTER_SANITIZE_ADD_SLASHES));
|
$username = trim(filter_input(INPUT_POST, 'username', FILTER_SANITIZE_ADD_SLASHES));
|
||||||
@@ -41,7 +47,7 @@ class Register extends Renderer {
|
|||||||
if (filter_input(INPUT_POST, 'accept', FILTER_SANITIZE_NUMBER_INT) !== '1') {
|
if (filter_input(INPUT_POST, 'accept', FILTER_SANITIZE_NUMBER_INT) !== '1') {
|
||||||
$this->errors['accept'] = 'Sie müssen der Speicherung Ihrer Daten zustimmen.';
|
$this->errors['accept'] = 'Sie müssen der Speicherung Ihrer Daten zustimmen.';
|
||||||
}
|
}
|
||||||
return (count($errors) === 0);
|
return (count($this->errors) === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function writeToDb(): void {
|
protected function writeToDb(): void {
|
||||||
|
|||||||
@@ -461,7 +461,12 @@ class Renderer {
|
|||||||
$mail->addStringAttachment($attachment['content'], $fileName, 'base64', $attachment['type']);
|
$mail->addStringAttachment($attachment['content'], $fileName, 'base64', $attachment['type']);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
$mail->send();
|
$mail->send();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log('Mailversand fehlgeschlagen: ' . $e->getMessage());
|
||||||
|
$this->errors[] = 'Die Bestätigungs-Email konnte nicht versendet werden. Bitte versuchen Sie es später erneut oder kontaktieren Sie uns direkt.';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function connectToImap($folder = ''): bool {
|
protected function connectToImap($folder = ''): bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user