diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/controller/ajax.php | 18 | ||||
-rw-r--r-- | src/model/entities/Node.php | 2 | ||||
-rw-r--r-- | src/view/FormBuilder.php | 23 | ||||
-rw-r--r-- | src/view/templates/form.php | 2 |
4 files changed, 33 insertions, 12 deletions
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'){ | |||
353 | echo json_encode(['success' => true]); | 353 | echo json_encode(['success' => true]); |
354 | die; | 354 | die; |
355 | } | 355 | } |
356 | |||
357 | // config formulaire | ||
358 | elseif($_GET['action'] === 'recipient_email'){ | ||
359 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | ||
360 | $email = htmlspecialchars(trim($json['email'])); | ||
361 | |||
362 | if(filter_var($email, FILTER_VALIDATE_EMAIL)){ | ||
363 | $form_data->updateData('email', $json['email']); | ||
364 | $entityManager->persist($form_data); | ||
365 | $entityManager->flush(); | ||
366 | echo json_encode(['success' => true]); | ||
367 | die; | ||
368 | } | ||
369 | else{ | ||
370 | echo json_encode(['success' => false]); | ||
371 | die; | ||
372 | } | ||
373 | } | ||
356 | } | 374 | } |
357 | 375 | ||
358 | 376 | ||
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 | |||
56 | 56 | ||
57 | private array $children = []; // tableau de Node | 57 | private array $children = []; // tableau de Node |
58 | private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article" | 58 | private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article" |
59 | static private array $default_attributes = ['css_array' => ['body', 'head', 'nav', 'foot', 'calendar'],'js_array' => ['main']]; | 59 | static private array $default_attributes = ['css_array' => ['body', 'head', 'nav', 'foot'],'js_array' => ['main']]; |
60 | 60 | ||
61 | public function __construct(string $name = '', ?string $article_timestamp = null, array $attributes = [], int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null) | 61 | public function __construct(string $name = '', ?string $article_timestamp = null, array $attributes = [], int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null) |
62 | { | 62 | { |
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 | |||
23 | $captcha = new Captcha; | 23 | $captcha = new Captcha; |
24 | $_SESSION['captcha'] = $captcha->getSolution(); | 24 | $_SESSION['captcha'] = $captcha->getSolution(); |
25 | 25 | ||
26 | $no_recipient_warning = ''; | 26 | $recipient_found = false; |
27 | if(isset($email)){ | ||
28 | $recipient_found = true; | ||
29 | } | ||
30 | else{ | ||
31 | $email = ''; | ||
32 | } | ||
33 | |||
27 | $admin_content = ''; | 34 | $admin_content = ''; |
28 | if($_SESSION['admin']) | 35 | if($_SESSION['admin']) |
29 | { | 36 | { |
30 | $admin_content = '<script src="js/form.js"></script> | 37 | $admin_content = '<script src="js/form.js"></script> |
31 | <h3>Configuration du formulaire</h3> | 38 | <h3>Configuration du formulaire</h3> |
32 | <div class="admin_form"> | 39 | <div class="admin_form"> |
33 | <label for="recipient">E-mail du destinataire</label> | 40 | <label for="recipient">E-mail de destination</label> |
34 | <input id="recipient" type="email" name="recipient" placeholder="mon-adresse@email.fr" value=""> | 41 | <input id="recipient" type="email" name="recipient" placeholder="mon-adresse@email.fr" value="' . $email . '"> |
35 | <button onclick="changeRecipient()">Valider</button> | 42 | <button onclick="changeRecipient(' . $node->getNodeData()->getId() . ')">Valider</button> |
36 | </div>'; | 43 | </div>'; |
37 | } | 44 | } |
38 | |||
39 | $recipient_found = false; | ||
40 | // recherche BDD | ||
41 | 45 | ||
42 | if(!$recipient_found){ // vérifier qu'une adresse de destination est bien configurée | 46 | // 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>'; | 47 | $no_recipient_warning = '<p class="no_recipient_warning ' . ($recipient_found ? 'hidden' : '') . '">Aucune adresse de destination n\'a été configurée, envoi d\'e-mail impossible!</p>'; |
44 | } | ||
45 | 48 | ||
46 | ob_start(); | 49 | ob_start(); |
47 | require $viewFile; | 50 | 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 @@ | |||
4 | <h3><?= $title ?></h3> | 4 | <h3><?= $title ?></h3> |
5 | <?= $no_recipient_warning ?> | 5 | <?= $no_recipient_warning ?> |
6 | <form method="post" action="<?= $action_url ?>"> | 6 | <form method="post" action="<?= $action_url ?>"> |
7 | <label for="email">Adresse e-mail</label> | 7 | <label for="email">Votre e-mail</label> |
8 | <input type="email" name="email" placeholder="mon-adresse@email.fr" value="" required> | 8 | <input type="email" name="email" placeholder="mon-adresse@email.fr" value="" required> |
9 | 9 | ||
10 | <label for="subject">Objet</label> | 10 | <label for="subject">Objet</label> |