diff options
| author | polo <ordipolo@gmx.fr> | 2025-08-03 00:23:11 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-08-03 00:23:11 +0200 |
| commit | 547d7feed68e89957f062b8ed9b988f28c5830ce (patch) | |
| tree | 7e07ea2b2065468900201cddacad5db559446a7d /src/controller/ContactFormController.php | |
| parent | 9934a32f7e02c484d6b122c9af860ab1ca9b2dca (diff) | |
| download | cms-547d7feed68e89957f062b8ed9b988f28c5830ce.tar.gz cms-547d7feed68e89957f062b8ed9b988f28c5830ce.tar.bz2 cms-547d7feed68e89957f062b8ed9b988f28c5830ce.zip | |
réorganisation 3: classes controller
Diffstat (limited to 'src/controller/ContactFormController.php')
| -rw-r--r-- | src/controller/ContactFormController.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/controller/ContactFormController.php b/src/controller/ContactFormController.php new file mode 100644 index 0000000..9d62a77 --- /dev/null +++ b/src/controller/ContactFormController.php | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | <?php | ||
| 2 | // src/controller/ContactFormController.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | use Doctrine\ORM\EntityManager; | ||
| 7 | |||
| 8 | class ContactFormController | ||
| 9 | { | ||
| 10 | static public function updateRecipient(EntityManager $entityManager, array $json): void | ||
| 11 | { | ||
| 12 | $email = htmlspecialchars(trim($json['email'])); | ||
| 13 | |||
| 14 | if((filter_var($email, FILTER_VALIDATE_EMAIL) // nouvel e-mail | ||
| 15 | || ($json['email'] === '' && !empty(Config::$email_dest))) // e-mail par défaut | ||
| 16 | && isset($json['hidden']) && empty($json['hidden'])) | ||
| 17 | { | ||
| 18 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | ||
| 19 | $form_data->updateData('email', $email); | ||
| 20 | $entityManager->persist($form_data); | ||
| 21 | $entityManager->flush(); | ||
| 22 | |||
| 23 | echo json_encode(['success' => true]); | ||
| 24 | } | ||
| 25 | else{ | ||
| 26 | echo json_encode(['success' => false]); | ||
| 27 | } | ||
| 28 | die; | ||
| 29 | } | ||
| 30 | static public function sendTestEmail(EntityManager $entityManager, array $json): void | ||
| 31 | { | ||
| 32 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur | ||
| 33 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | ||
| 34 | $recipient = $form_data->getData()['email'] ?? Config::$email_dest; | ||
| 35 | |||
| 36 | if(EmailController::send($recipient, false, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){ | ||
| 37 | echo json_encode(['success' => true]); | ||
| 38 | } | ||
| 39 | else{ | ||
| 40 | echo json_encode(['success' => false]); | ||
| 41 | } | ||
| 42 | die; | ||
| 43 | } | ||
| 44 | } \ No newline at end of file | ||
