From ef60a4bd581ec9fb85384c6a262b499373a37d67 Mon Sep 17 00:00:00 2001 From: polo Date: Sat, 28 Jun 2025 10:34:25 +0200 Subject: formulaire de contact 1 --- public/css/form.css | 54 +++++++++++++++++++++++++++++++++++++++++++++ public/css/modif_page.css | 4 ++-- public/js/form.js | 28 +++++++++++++++++++++++ src/controller/post.php | 8 +++---- src/model/EventDTO.php | 2 ++ src/view/FormBuilder.php | 51 ++++++++++++++++++++++++++++++++++++++++++ src/view/MainBuilder.php | 25 +++++++++++++++------ src/view/templates/form.php | 32 +++++++++++++++++++++++++++ 8 files changed, 191 insertions(+), 13 deletions(-) create mode 100644 public/css/form.css create mode 100644 public/js/form.js create mode 100644 src/view/FormBuilder.php create mode 100644 src/view/templates/form.php diff --git a/public/css/form.css b/public/css/form.css new file mode 100644 index 0000000..473252c --- /dev/null +++ b/public/css/form.css @@ -0,0 +1,54 @@ +.form form{ + background-color: white; + margin: auto; + padding: 10px; + max-width: 800px; + display: grid; + grid-template-columns: auto 1fr; + gap: 10px; + align-items: center; /* vertical */ +} +.form label{ + text-align: right; +} +.form .full_width_column{ + grid-column: 1 / span 2; +} +.form form input[type=submit] +{ + color: #ff1d04; + font-size: medium; + border-radius: 4px; + background-color: white; + border: lightgrey 2px outset; +} +.form form input[type=submit]:hover +{ + background-color: #ffff00; + border-radius: 4px; + cursor: pointer; +} + +.no_recipient_warning{ + color: red; + text-align: center; +} + +.form .admin_form{ + background-color: #f0f0f0; + margin: auto; + padding: 10px; + max-width: 800px; +} + +@media screen and (max-width: 600px){ + .form form{ + grid-template-columns: 1fr; + } + .form label{ + text-align: left; + } + .form .full_width_column { + grid-column: 1; + } +} \ No newline at end of file diff --git a/public/css/modif_page.css b/public/css/modif_page.css index d743e9e..77392d2 100644 --- a/public/css/modif_page.css +++ b/public/css/modif_page.css @@ -13,10 +13,10 @@ background-color: white; border: lightgrey 2px outset; } -.page_modificationselect:hover +/*.page_modification select:hover { cursor: pointer; -} +}*/ .page_modification form input[type=submit]:hover { background-color: #ffff00; diff --git a/public/js/form.js b/public/js/form.js new file mode 100644 index 0000000..6386ea8 --- /dev/null +++ b/public/js/form.js @@ -0,0 +1,28 @@ +//function sendMessage(){} + +function changeRecipient(){ + const email = document.getElementById('recipient').value; + const id_form = ''; + + fetch('index.php?action=recipient_email', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ id_form: id_form, email: email }) + }) + .then(response => response.json()) + .then(data => { + if(data.success) + { + toastNotify('Adresse e-mail de destination modifiée'); + } + else { + + console.error('Erreur: echec de la modification de l\'adresse e-mail de destination'); + } + }) + .catch(error => { + console.error('Erreur:', error); + }); +} \ No newline at end of file diff --git a/src/controller/post.php b/src/controller/post.php index 7e6ed53..acad1ce 100644 --- a/src/controller/post.php +++ b/src/controller/post.php @@ -132,14 +132,14 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) $main = $director->getNode(); $position = count($main->getChildren()) + 1; // position dans la fraterie - $blocs_true_names = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans FormBuilder.php - if(!in_array($_POST["bloc_select"], $blocs_true_names, true)) // 3è param: contrôle du type + $blocks = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans FormBuilder.php + if(!in_array($_POST["bloc_select"], $blocks, true)) // 3è param: contrôle du type { header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'bad_bloc_type'])); die; } - if($_POST["bloc_select"] === 'calendar'){ + if($_POST["bloc_select"] === 'calendar' || $_POST["bloc_select"] === 'form'){ $dql = 'SELECT n FROM App\Entity\Node n WHERE n.page = :page AND n.name_node = :name'; // noeud 'head' de la page $bulk_data = $entityManager ->createQuery($dql) @@ -152,7 +152,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) die; } - $bulk_data[0]->addAttribute('css_array', 'calendar'); + $bulk_data[0]->addAttribute('css_array', $_POST["bloc_select"]); $entityManager->persist($bulk_data[0]); } diff --git a/src/model/EventDTO.php b/src/model/EventDTO.php index 8d33733..70013dd 100644 --- a/src/model/EventDTO.php +++ b/src/model/EventDTO.php @@ -4,6 +4,8 @@ // classe de données JSONifiable compatible avec fullcalendar // servira aussi pour l'import/export de fichiers .ics +declare(strict_types=1); + use App\Entity\Event; class EventDTO diff --git a/src/view/FormBuilder.php b/src/view/FormBuilder.php new file mode 100644 index 0000000..b3a96f3 --- /dev/null +++ b/src/view/FormBuilder.php @@ -0,0 +1,51 @@ +getName() . '.php'; + + if(file_exists($viewFile)) + { + if(!empty($node->getNodeData()->getData())) + { + extract($node->getNodeData()->getData()); + } + + $action_url = new URL(['page' => CURRENT_PAGE]); + $captcha = new Captcha; + $_SESSION['captcha'] = $captcha->getSolution(); + + $no_recipient_warning = ''; + $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!

'; + } + + ob_start(); + require $viewFile; + $this->html = ob_get_clean(); // pas de concaténation ici, on écrase + } + } +} \ No newline at end of file diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php index a478412..4bd79c3 100644 --- a/src/view/MainBuilder.php +++ b/src/view/MainBuilder.php @@ -54,13 +54,25 @@ class MainBuilder extends AbstractBuilder { $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; // mode modification uniquement - // blocs disponibles - $blocs = ['Blog', 'Grille', 'Calendrier', 'Galerie', 'Formulaire']; // générer ça dynamiquement! - $blocs_true_names = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans post.php + // blocs disponibles, même liste dans post.php + $blocks = [ // créer une classe pour ça? + ['type' => 'blog', 'name' => 'Blog'], + ['type' => 'grid', 'name' => 'Grille'], + ['type' => 'calendar', 'name' => 'Calendrier'], + ['type' => 'galery', 'name' => 'Galerie'], + ['type' => 'form', 'name' => 'Formulaire']]; + + function getBlockName(array $blocks, string $type){ // créer une classe pour ça? + for($i=0; $i < count($blocks); $i++){ + if($blocks[$i]['type'] === $type){ + return $blocks[$i]['name']; + } + } + } $options = ''; - for($i = 0; $i < count($blocs); $i++){ - $options .= '\n"; + for($i = 0; $i < count($blocks); $i++){ + $options .= '\n"; } // blabla @@ -85,8 +97,7 @@ class MainBuilder extends AbstractBuilder foreach($node->getChildren() as $child_node){ // renommage d'un bloc $bloc_edit .= '
-

- +

'. "\n"; // déplacement d'un bloc diff --git a/src/view/templates/form.php b/src/view/templates/form.php new file mode 100644 index 0000000..97d53d4 --- /dev/null +++ b/src/view/templates/form.php @@ -0,0 +1,32 @@ + +

+ +

+ +
+ + + + + + + + + +
+ +
+ + +
+ +
+ + + + +
+ +
+
+
\ No newline at end of file -- cgit v1.2.3