From ea3eaf84c6de3f96d6bb73e817147f8571fd6c1f Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 30 Jun 2025 17:22:26 +0200 Subject: formulaire de contact 2 --- src/controller/ajax.php | 18 ++++++++++++++++++ src/model/entities/Node.php | 2 +- src/view/FormBuilder.php | 23 +++++++++++++---------- src/view/templates/form.php | 2 +- 4 files changed, 33 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/controller/ajax.php b/src/controller/ajax.php index a462921..ae43b75 100644 --- a/src/controller/ajax.php +++ b/src/controller/ajax.php @@ -353,6 +353,24 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json'){ echo json_encode(['success' => true]); die; } + + // config formulaire + elseif($_GET['action'] === 'recipient_email'){ + $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); + $email = htmlspecialchars(trim($json['email'])); + + if(filter_var($email, FILTER_VALIDATE_EMAIL)){ + $form_data->updateData('email', $json['email']); + $entityManager->persist($form_data); + $entityManager->flush(); + echo json_encode(['success' => true]); + die; + } + else{ + echo json_encode(['success' => false]); + die; + } + } } diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php index c4d0830..93363d3 100644 --- a/src/model/entities/Node.php +++ b/src/model/entities/Node.php @@ -56,7 +56,7 @@ class Node private array $children = []; // tableau de Node private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article" - static private array $default_attributes = ['css_array' => ['body', 'head', 'nav', 'foot', 'calendar'],'js_array' => ['main']]; + static private array $default_attributes = ['css_array' => ['body', 'head', 'nav', 'foot'],'js_array' => ['main']]; public function __construct(string $name = '', ?string $article_timestamp = null, array $attributes = [], int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null) { diff --git a/src/view/FormBuilder.php b/src/view/FormBuilder.php index b3a96f3..5f8545c 100644 --- a/src/view/FormBuilder.php +++ b/src/view/FormBuilder.php @@ -23,25 +23,28 @@ class FormBuilder extends AbstractBuilder $captcha = new Captcha; $_SESSION['captcha'] = $captcha->getSolution(); - $no_recipient_warning = ''; + $recipient_found = false; + if(isset($email)){ + $recipient_found = true; + } + else{ + $email = ''; + } + $admin_content = ''; if($_SESSION['admin']) { $admin_content = '

Configuration du formulaire

- - - + + +
'; } - - $recipient_found = false; - // recherche BDD - if(!$recipient_found){ // vérifier qu'une adresse de destination est bien configurée - $no_recipient_warning = '

Aucune adresse de destination n\'a été configurée, envoi d\'e-mail impossible!

'; - } + // vérifier qu'une adresse de destination est bien configurée + $no_recipient_warning = '

Aucune adresse de destination n\'a été configurée, envoi d\'e-mail impossible!

'; ob_start(); require $viewFile; diff --git a/src/view/templates/form.php b/src/view/templates/form.php index 97d53d4..0c44bf8 100644 --- a/src/view/templates/form.php +++ b/src/view/templates/form.php @@ -4,7 +4,7 @@

- + -- cgit v1.2.3