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 --- public/css/body.css | 4 ++++ public/css/tinymce.css | 4 ++-- public/js/form.js | 15 +++++++-------- src/controller/ajax.php | 18 ++++++++++++++++++ src/model/entities/Node.php | 2 +- src/view/FormBuilder.php | 23 +++++++++++++---------- src/view/templates/form.php | 2 +- 7 files changed, 46 insertions(+), 22 deletions(-) diff --git a/public/css/body.css b/public/css/body.css index a2b099a..eb198e6 100644 --- a/public/css/body.css +++ b/public/css/body.css @@ -7,6 +7,10 @@ body background-color: #0cceec; } +.hidden{ + display: none; +} + #bloc_page {} diff --git a/public/css/tinymce.css b/public/css/tinymce.css index 55639e0..1a99de9 100644 --- a/public/css/tinymce.css +++ b/public/css/tinymce.css @@ -1,6 +1,6 @@ .tox-promotion{ display: none; } -.hidden{ +/*.hidden{ display: none; -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/public/js/form.js b/public/js/form.js index 6386ea8..1752f55 100644 --- a/public/js/form.js +++ b/public/js/form.js @@ -1,24 +1,23 @@ //function sendMessage(){} -function changeRecipient(){ +function changeRecipient(id){ const email = document.getElementById('recipient').value; - const id_form = ''; + const warning = document.querySelector('.no_recipient_warning'); fetch('index.php?action=recipient_email', { method: 'POST', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json' }, - body: JSON.stringify({ id_form: id_form, email: email }) + body: JSON.stringify({ id: id, email: email }) }) .then(response => response.json()) .then(data => { - if(data.success) - { + if(data.success){ + warning.classList.add('hidden'); toastNotify('Adresse e-mail de destination modifiée'); } - else { - + else{ console.error('Erreur: echec de la modification de l\'adresse e-mail de destination'); } }) 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