From 2d7bacce891eab0adb0263d598bfe44418788f42 Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 4 Jul 2025 00:43:35 +0200 Subject: formulaire de contact 3 --- public/js/form.js | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 3 deletions(-) (limited to 'public/js/form.js') 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 @@ //function sendMessage(){} -function changeRecipient(id){ +// modif des paramètre d'envoi d'e-mail depuis l'espace admin +/*function changeRecipient(id){ const email = document.getElementById('recipient').value; + const hidden = document.getElementById('recipient_hidden').value; const warning = document.querySelector('.no_recipient_warning'); fetch('index.php?action=recipient_email', { @@ -9,7 +11,7 @@ function changeRecipient(id){ headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ id: id, email: email }) + body: JSON.stringify({ id: id, email: email, hidden: hidden }) }) .then(response => response.json()) .then(data => { @@ -18,10 +20,89 @@ function changeRecipient(id){ toastNotify('Adresse e-mail de destination modifiée'); } else{ - console.error('Erreur: echec de la modification de l\'adresse e-mail de destination'); + toastNotify('E-mail non valide'); } }) .catch(error => { console.error('Erreur:', error); }); +}*/ + +function sendTestEmail(){ + const admin_form = document.querySelector('.admin_form'); + const test_email_success = document.querySelector('.test_email_success'); + test_email_success.innerHTML = 'Envoi en cours, veuillez patienter'; + test_email_success.style.backgroundColor = '#f0f0f0'; + + fetch('index.php?action=test_email', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({}) + }) + .then(response => response.json()) + .then(data => { + let message; + let color; + if(data.success){ + message = 'E-mail de test envoyé avec succès'; + color = 'lawngreen'; + } + else{ + message = "Erreur à l'envoi de l'e-mail"; + color = "orangered" + } + test_email_success.innerHTML = message; + toastNotify(message); + test_email_success.style.backgroundColor = color; + }) + .catch(error => { + console.error('Erreur:', error); + }); +} + +function sendVisitorEmail(){ + const send_email_success = document.querySelector('.send_email_success'); + send_email_success.innerHTML = 'Envoi en cours, veuillez patienter'; + send_email_success.style.backgroundColor = 'initial'; + + const email_name = document.getElementById('email_name').value; + const email_address = document.getElementById('email_address').value; + const email_message = document.getElementById('email_message').value; + const email_captcha = document.getElementById('email_captcha').value; + const email_hidden = document.getElementById('email_hidden').value; + + fetch('index.php?action=send_email', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + name: email_name, + email: email_address, + message: email_message, + captcha: email_captcha, + hidden: email_hidden + }) + }) + .then(response => response.json()) + .then(data => { + let message; + let color; + if(data.success){ + message = 'Votre E-mail a été envoyé!'; + color = 'lawngreen'; + } + else{ + message = "Votre message n'a pas pu être envoyé, votre e-mail ou le captcha ne sont peut-être pas corrects"; + color = "orangered" + } + send_email_success.innerHTML = message; + toastNotify(message); + send_email_success.style.backgroundColor = color; + }) + .catch(error => { + console.error('Erreur:', error); + }); } \ No newline at end of file -- cgit v1.2.3