diff options
| author | polo <ordipolo@gmx.fr> | 2025-06-28 10:34:25 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-06-28 10:34:25 +0200 |
| commit | ef60a4bd581ec9fb85384c6a262b499373a37d67 (patch) | |
| tree | 7ae6d4aa39cf6128a0358634b371c3ed77c3a18b | |
| parent | f60a9d046088b3bad3e97ff568fc83fecc67ccde (diff) | |
| download | cms-ef60a4bd581ec9fb85384c6a262b499373a37d67.tar.gz cms-ef60a4bd581ec9fb85384c6a262b499373a37d67.tar.bz2 cms-ef60a4bd581ec9fb85384c6a262b499373a37d67.zip | |
formulaire de contact 1
| -rw-r--r-- | public/css/form.css | 54 | ||||
| -rw-r--r-- | public/css/modif_page.css | 4 | ||||
| -rw-r--r-- | public/js/form.js | 28 | ||||
| -rw-r--r-- | src/controller/post.php | 8 | ||||
| -rw-r--r-- | src/model/EventDTO.php | 2 | ||||
| -rw-r--r-- | src/view/FormBuilder.php | 51 | ||||
| -rw-r--r-- | src/view/MainBuilder.php | 25 | ||||
| -rw-r--r-- | src/view/templates/form.php | 32 |
8 files changed, 191 insertions, 13 deletions
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 @@ | |||
| 1 | .form form{ | ||
| 2 | background-color: white; | ||
| 3 | margin: auto; | ||
| 4 | padding: 10px; | ||
| 5 | max-width: 800px; | ||
| 6 | display: grid; | ||
| 7 | grid-template-columns: auto 1fr; | ||
| 8 | gap: 10px; | ||
| 9 | align-items: center; /* vertical */ | ||
| 10 | } | ||
| 11 | .form label{ | ||
| 12 | text-align: right; | ||
| 13 | } | ||
| 14 | .form .full_width_column{ | ||
| 15 | grid-column: 1 / span 2; | ||
| 16 | } | ||
| 17 | .form form input[type=submit] | ||
| 18 | { | ||
| 19 | color: #ff1d04; | ||
| 20 | font-size: medium; | ||
| 21 | border-radius: 4px; | ||
| 22 | background-color: white; | ||
| 23 | border: lightgrey 2px outset; | ||
| 24 | } | ||
| 25 | .form form input[type=submit]:hover | ||
| 26 | { | ||
| 27 | background-color: #ffff00; | ||
| 28 | border-radius: 4px; | ||
| 29 | cursor: pointer; | ||
| 30 | } | ||
| 31 | |||
| 32 | .no_recipient_warning{ | ||
| 33 | color: red; | ||
| 34 | text-align: center; | ||
| 35 | } | ||
| 36 | |||
| 37 | .form .admin_form{ | ||
| 38 | background-color: #f0f0f0; | ||
| 39 | margin: auto; | ||
| 40 | padding: 10px; | ||
| 41 | max-width: 800px; | ||
| 42 | } | ||
| 43 | |||
| 44 | @media screen and (max-width: 600px){ | ||
| 45 | .form form{ | ||
| 46 | grid-template-columns: 1fr; | ||
| 47 | } | ||
| 48 | .form label{ | ||
| 49 | text-align: left; | ||
| 50 | } | ||
| 51 | .form .full_width_column { | ||
| 52 | grid-column: 1; | ||
| 53 | } | ||
| 54 | } \ 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 @@ | |||
| 13 | background-color: white; | 13 | background-color: white; |
| 14 | border: lightgrey 2px outset; | 14 | border: lightgrey 2px outset; |
| 15 | } | 15 | } |
| 16 | .page_modificationselect:hover | 16 | /*.page_modification select:hover |
| 17 | { | 17 | { |
| 18 | cursor: pointer; | 18 | cursor: pointer; |
| 19 | } | 19 | }*/ |
| 20 | .page_modification form input[type=submit]:hover | 20 | .page_modification form input[type=submit]:hover |
| 21 | { | 21 | { |
| 22 | background-color: #ffff00; | 22 | 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 @@ | |||
| 1 | //function sendMessage(){} | ||
| 2 | |||
| 3 | function changeRecipient(){ | ||
| 4 | const email = document.getElementById('recipient').value; | ||
| 5 | const id_form = ''; | ||
| 6 | |||
| 7 | fetch('index.php?action=recipient_email', { | ||
| 8 | method: 'POST', | ||
| 9 | headers: { | ||
| 10 | 'Content-Type': 'application/json' | ||
| 11 | }, | ||
| 12 | body: JSON.stringify({ id_form: id_form, email: email }) | ||
| 13 | }) | ||
| 14 | .then(response => response.json()) | ||
| 15 | .then(data => { | ||
| 16 | if(data.success) | ||
| 17 | { | ||
| 18 | toastNotify('Adresse e-mail de destination modifiée'); | ||
| 19 | } | ||
| 20 | else { | ||
| 21 | |||
| 22 | console.error('Erreur: echec de la modification de l\'adresse e-mail de destination'); | ||
| 23 | } | ||
| 24 | }) | ||
| 25 | .catch(error => { | ||
| 26 | console.error('Erreur:', error); | ||
| 27 | }); | ||
| 28 | } \ 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) | |||
| 132 | $main = $director->getNode(); | 132 | $main = $director->getNode(); |
| 133 | $position = count($main->getChildren()) + 1; // position dans la fraterie | 133 | $position = count($main->getChildren()) + 1; // position dans la fraterie |
| 134 | 134 | ||
| 135 | $blocs_true_names = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans FormBuilder.php | 135 | $blocks = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans FormBuilder.php |
| 136 | if(!in_array($_POST["bloc_select"], $blocs_true_names, true)) // 3è param: contrôle du type | 136 | if(!in_array($_POST["bloc_select"], $blocks, true)) // 3è param: contrôle du type |
| 137 | { | 137 | { |
| 138 | header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'bad_bloc_type'])); | 138 | header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'bad_bloc_type'])); |
| 139 | die; | 139 | die; |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | if($_POST["bloc_select"] === 'calendar'){ | 142 | if($_POST["bloc_select"] === 'calendar' || $_POST["bloc_select"] === 'form'){ |
| 143 | $dql = 'SELECT n FROM App\Entity\Node n WHERE n.page = :page AND n.name_node = :name'; // noeud 'head' de la page | 143 | $dql = 'SELECT n FROM App\Entity\Node n WHERE n.page = :page AND n.name_node = :name'; // noeud 'head' de la page |
| 144 | $bulk_data = $entityManager | 144 | $bulk_data = $entityManager |
| 145 | ->createQuery($dql) | 145 | ->createQuery($dql) |
| @@ -152,7 +152,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
| 152 | die; | 152 | die; |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | $bulk_data[0]->addAttribute('css_array', 'calendar'); | 155 | $bulk_data[0]->addAttribute('css_array', $_POST["bloc_select"]); |
| 156 | $entityManager->persist($bulk_data[0]); | 156 | $entityManager->persist($bulk_data[0]); |
| 157 | } | 157 | } |
| 158 | 158 | ||
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 @@ | |||
| 4 | // classe de données JSONifiable compatible avec fullcalendar | 4 | // classe de données JSONifiable compatible avec fullcalendar |
| 5 | // servira aussi pour l'import/export de fichiers .ics | 5 | // servira aussi pour l'import/export de fichiers .ics |
| 6 | 6 | ||
| 7 | declare(strict_types=1); | ||
| 8 | |||
| 7 | use App\Entity\Event; | 9 | use App\Entity\Event; |
| 8 | 10 | ||
| 9 | class EventDTO | 11 | 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 @@ | |||
| 1 | <?php | ||
| 2 | // src/view/FormBuilder.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | use App\Entity\Node; | ||
| 7 | |||
| 8 | class FormBuilder extends AbstractBuilder | ||
| 9 | { | ||
| 10 | public function __construct(Node $node) | ||
| 11 | { | ||
| 12 | parent::__construct($node); | ||
| 13 | $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; | ||
| 14 | |||
| 15 | if(file_exists($viewFile)) | ||
| 16 | { | ||
| 17 | if(!empty($node->getNodeData()->getData())) | ||
| 18 | { | ||
| 19 | extract($node->getNodeData()->getData()); | ||
| 20 | } | ||
| 21 | |||
| 22 | $action_url = new URL(['page' => CURRENT_PAGE]); | ||
| 23 | $captcha = new Captcha; | ||
| 24 | $_SESSION['captcha'] = $captcha->getSolution(); | ||
| 25 | |||
| 26 | $no_recipient_warning = ''; | ||
| 27 | $admin_content = ''; | ||
| 28 | if($_SESSION['admin']) | ||
| 29 | { | ||
| 30 | $admin_content = '<script src="js/form.js"></script> | ||
| 31 | <h3>Configuration du formulaire</h3> | ||
| 32 | <div class="admin_form"> | ||
| 33 | <label for="recipient">E-mail du destinataire</label> | ||
| 34 | <input id="recipient" type="email" name="recipient" placeholder="mon-adresse@email.fr" value=""> | ||
| 35 | <button onclick="changeRecipient()">Valider</button> | ||
| 36 | </div>'; | ||
| 37 | } | ||
| 38 | |||
| 39 | $recipient_found = false; | ||
| 40 | // recherche BDD | ||
| 41 | |||
| 42 | if(!$recipient_found){ // vérifier qu'une adresse de destination est bien configurée | ||
| 43 | $no_recipient_warning = '<p class="no_recipient_warning">Aucune adresse de destination n\'a été configurée, envoi d\'e-mail impossible!</p>'; | ||
| 44 | } | ||
| 45 | |||
| 46 | ob_start(); | ||
| 47 | require $viewFile; | ||
| 48 | $this->html = ob_get_clean(); // pas de concaténation ici, on écrase | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } \ 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 | |||
| 54 | { | 54 | { |
| 55 | $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; // mode modification uniquement | 55 | $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; // mode modification uniquement |
| 56 | 56 | ||
| 57 | // blocs disponibles | 57 | // blocs disponibles, même liste dans post.php |
| 58 | $blocs = ['Blog', 'Grille', 'Calendrier', 'Galerie', 'Formulaire']; // générer ça dynamiquement! | 58 | $blocks = [ // créer une classe pour ça? |
| 59 | $blocs_true_names = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans post.php | 59 | ['type' => 'blog', 'name' => 'Blog'], |
| 60 | ['type' => 'grid', 'name' => 'Grille'], | ||
| 61 | ['type' => 'calendar', 'name' => 'Calendrier'], | ||
| 62 | ['type' => 'galery', 'name' => 'Galerie'], | ||
| 63 | ['type' => 'form', 'name' => 'Formulaire']]; | ||
| 64 | |||
| 65 | function getBlockName(array $blocks, string $type){ // créer une classe pour ça? | ||
| 66 | for($i=0; $i < count($blocks); $i++){ | ||
| 67 | if($blocks[$i]['type'] === $type){ | ||
| 68 | return $blocks[$i]['name']; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 60 | 72 | ||
| 61 | $options = ''; | 73 | $options = ''; |
| 62 | for($i = 0; $i < count($blocs); $i++){ | 74 | for($i = 0; $i < count($blocks); $i++){ |
| 63 | $options .= '<option value= "' . $blocs_true_names[$i] . '">' . $blocs[$i] . "</option>\n"; | 75 | $options .= '<option value= "' . $blocks[$i]['type'] . '">' . $blocks[$i]['name'] . "</option>\n"; |
| 64 | } | 76 | } |
| 65 | 77 | ||
| 66 | // blabla | 78 | // blabla |
| @@ -85,8 +97,7 @@ class MainBuilder extends AbstractBuilder | |||
| 85 | foreach($node->getChildren() as $child_node){ | 97 | foreach($node->getChildren() as $child_node){ |
| 86 | // renommage d'un bloc | 98 | // renommage d'un bloc |
| 87 | $bloc_edit .= '<div id="bloc_edit_' . $child_node->getId() . '"> | 99 | $bloc_edit .= '<div id="bloc_edit_' . $child_node->getId() . '"> |
| 88 | <p><label>Type <i>' . $child_node->getName() . '</i>, </label> | 100 | <p><label for="bloc_rename_' . $child_node->getId() . '"><b>' . getBlockName($blocks, $child_node->getName()) . '</b></label> |
| 89 | <label for="bloc_rename_' . $child_node->getId() . '">Titre</label> | ||
| 90 | <input type="text" id="bloc_rename_' . $child_node->getId() . '" name="bloc_rename_title" value="' . $child_node->getNodeData()->getdata()['title'] . '" required> | 101 | <input type="text" id="bloc_rename_' . $child_node->getId() . '" name="bloc_rename_title" value="' . $child_node->getNodeData()->getdata()['title'] . '" required> |
| 91 | <button onclick="renamePageBloc(' . $child_node->getId() . ')">Renommer</button>'. "\n"; | 102 | <button onclick="renamePageBloc(' . $child_node->getId() . ')">Renommer</button>'. "\n"; |
| 92 | // déplacement d'un bloc | 103 | // 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 @@ | |||
| 1 | <?php declare(strict_types=1); ?> | ||
| 2 | <section class="form" id="<?= $this->id_node ?>"> | ||
| 3 | <?= $admin_content ?> | ||
| 4 | <h3><?= $title ?></h3> | ||
| 5 | <?= $no_recipient_warning ?> | ||
| 6 | <form method="post" action="<?= $action_url ?>"> | ||
| 7 | <label for="email">Adresse e-mail</label> | ||
| 8 | <input type="email" name="email" placeholder="mon-adresse@email.fr" value="" required> | ||
| 9 | |||
| 10 | <label for="subject">Objet</label> | ||
| 11 | <input type="text" name="subject" value="" required> | ||
| 12 | |||
| 13 | <label for="message">Votre message</label> | ||
| 14 | <textarea type="text" name="message" rows="4" required></textarea> | ||
| 15 | |||
| 16 | <div class="full_width_column"> | ||
| 17 | <label for="captcha" >Montrez que vous n'êtes pas un robot</label> | ||
| 18 | </div> | ||
| 19 | |||
| 20 | <label for="captcha" >Combien font <?= $captcha->getA() ?> fois <?= $captcha->getB() ?>?</label> | ||
| 21 | <div> | ||
| 22 | <input type="text" name="captcha" size="1" required> | ||
| 23 | </div> | ||
| 24 | |||
| 25 | <input type="hidden" name="form_id" value=""> | ||
| 26 | <input type="hidden" name="form_hidden"> | ||
| 27 | |||
| 28 | <div class="full_width_column"> | ||
| 29 | <input type="submit" value="Envoyez votre message"> | ||
| 30 | </div> | ||
| 31 | </form> | ||
| 32 | </section> \ No newline at end of file | ||
