diff options
| author | polo <ordipolo@gmx.fr> | 2025-07-04 00:43:35 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-07-04 00:43:35 +0200 |
| commit | 2d7bacce891eab0adb0263d598bfe44418788f42 (patch) | |
| tree | 4353250f80cc556a278640f22c194a0033d05829 /public/js | |
| parent | ea3eaf84c6de3f96d6bb73e817147f8571fd6c1f (diff) | |
| download | cms-2d7bacce891eab0adb0263d598bfe44418788f42.tar.gz cms-2d7bacce891eab0adb0263d598bfe44418788f42.tar.bz2 cms-2d7bacce891eab0adb0263d598bfe44418788f42.zip | |
formulaire de contact 3
Diffstat (limited to 'public/js')
| -rw-r--r-- | public/js/form.js | 87 |
1 files changed, 84 insertions, 3 deletions
diff --git a/public/js/form.js b/public/js/form.js index 1752f55..0be2313 100644 --- a/public/js/form.js +++ b/public/js/form.js | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | //function sendMessage(){} | 1 | //function sendMessage(){} |
| 2 | 2 | ||
| 3 | function changeRecipient(id){ | 3 | // modif des paramètre d'envoi d'e-mail depuis l'espace admin |
| 4 | /*function changeRecipient(id){ | ||
| 4 | const email = document.getElementById('recipient').value; | 5 | const email = document.getElementById('recipient').value; |
| 6 | const hidden = document.getElementById('recipient_hidden').value; | ||
| 5 | const warning = document.querySelector('.no_recipient_warning'); | 7 | const warning = document.querySelector('.no_recipient_warning'); |
| 6 | 8 | ||
| 7 | fetch('index.php?action=recipient_email', { | 9 | fetch('index.php?action=recipient_email', { |
| @@ -9,7 +11,7 @@ function changeRecipient(id){ | |||
| 9 | headers: { | 11 | headers: { |
| 10 | 'Content-Type': 'application/json' | 12 | 'Content-Type': 'application/json' |
| 11 | }, | 13 | }, |
| 12 | body: JSON.stringify({ id: id, email: email }) | 14 | body: JSON.stringify({ id: id, email: email, hidden: hidden }) |
| 13 | }) | 15 | }) |
| 14 | .then(response => response.json()) | 16 | .then(response => response.json()) |
| 15 | .then(data => { | 17 | .then(data => { |
| @@ -18,10 +20,89 @@ function changeRecipient(id){ | |||
| 18 | toastNotify('Adresse e-mail de destination modifiée'); | 20 | toastNotify('Adresse e-mail de destination modifiée'); |
| 19 | } | 21 | } |
| 20 | else{ | 22 | else{ |
| 21 | console.error('Erreur: echec de la modification de l\'adresse e-mail de destination'); | 23 | toastNotify('E-mail non valide'); |
| 22 | } | 24 | } |
| 23 | }) | 25 | }) |
| 24 | .catch(error => { | 26 | .catch(error => { |
| 25 | console.error('Erreur:', error); | 27 | console.error('Erreur:', error); |
| 26 | }); | 28 | }); |
| 29 | }*/ | ||
| 30 | |||
| 31 | function sendTestEmail(){ | ||
| 32 | const admin_form = document.querySelector('.admin_form'); | ||
| 33 | const test_email_success = document.querySelector('.test_email_success'); | ||
| 34 | test_email_success.innerHTML = 'Envoi en cours, veuillez patienter'; | ||
| 35 | test_email_success.style.backgroundColor = '#f0f0f0'; | ||
| 36 | |||
| 37 | fetch('index.php?action=test_email', { | ||
| 38 | method: 'POST', | ||
| 39 | headers: { | ||
| 40 | 'Content-Type': 'application/json' | ||
| 41 | }, | ||
| 42 | body: JSON.stringify({}) | ||
| 43 | }) | ||
| 44 | .then(response => response.json()) | ||
| 45 | .then(data => { | ||
| 46 | let message; | ||
| 47 | let color; | ||
| 48 | if(data.success){ | ||
| 49 | message = 'E-mail de test envoyé avec succès'; | ||
| 50 | color = 'lawngreen'; | ||
| 51 | } | ||
| 52 | else{ | ||
| 53 | message = "Erreur à l'envoi de l'e-mail"; | ||
| 54 | color = "orangered" | ||
| 55 | } | ||
| 56 | test_email_success.innerHTML = message; | ||
| 57 | toastNotify(message); | ||
| 58 | test_email_success.style.backgroundColor = color; | ||
| 59 | }) | ||
| 60 | .catch(error => { | ||
| 61 | console.error('Erreur:', error); | ||
| 62 | }); | ||
| 63 | } | ||
| 64 | |||
| 65 | function sendVisitorEmail(){ | ||
| 66 | const send_email_success = document.querySelector('.send_email_success'); | ||
| 67 | send_email_success.innerHTML = 'Envoi en cours, veuillez patienter'; | ||
| 68 | send_email_success.style.backgroundColor = 'initial'; | ||
| 69 | |||
| 70 | const email_name = document.getElementById('email_name').value; | ||
| 71 | const email_address = document.getElementById('email_address').value; | ||
| 72 | const email_message = document.getElementById('email_message').value; | ||
| 73 | const email_captcha = document.getElementById('email_captcha').value; | ||
| 74 | const email_hidden = document.getElementById('email_hidden').value; | ||
| 75 | |||
| 76 | fetch('index.php?action=send_email', { | ||
| 77 | method: 'POST', | ||
| 78 | headers: { | ||
| 79 | 'Content-Type': 'application/json' | ||
| 80 | }, | ||
| 81 | body: JSON.stringify({ | ||
| 82 | name: email_name, | ||
| 83 | email: email_address, | ||
| 84 | message: email_message, | ||
| 85 | captcha: email_captcha, | ||
| 86 | hidden: email_hidden | ||
| 87 | }) | ||
| 88 | }) | ||
| 89 | .then(response => response.json()) | ||
| 90 | .then(data => { | ||
| 91 | let message; | ||
| 92 | let color; | ||
| 93 | if(data.success){ | ||
| 94 | message = 'Votre E-mail a été envoyé!'; | ||
| 95 | color = 'lawngreen'; | ||
| 96 | } | ||
| 97 | else{ | ||
| 98 | message = "Votre message n'a pas pu être envoyé, votre e-mail ou le captcha ne sont peut-être pas corrects"; | ||
| 99 | color = "orangered" | ||
| 100 | } | ||
| 101 | send_email_success.innerHTML = message; | ||
| 102 | toastNotify(message); | ||
| 103 | send_email_success.style.backgroundColor = color; | ||
| 104 | }) | ||
| 105 | .catch(error => { | ||
| 106 | console.error('Erreur:', error); | ||
| 107 | }); | ||
| 27 | } \ No newline at end of file | 108 | } \ No newline at end of file |
