From dba24b8c18aed84a71c3169b2df5598d62deab06 Mon Sep 17 00:00:00 2001 From: polo Date: Sun, 17 Aug 2025 19:46:20 +0200 Subject: =?UTF-8?q?classe=20FormValidation=20et=20am=C3=A9lioration=20des?= =?UTF-8?q?=20envois=20d'e-mail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/form.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'public/js/form.js') diff --git a/public/js/form.js b/public/js/form.js index 5c5a164..cf138e6 100644 --- a/public/js/form.js +++ b/public/js/form.js @@ -26,6 +26,12 @@ function changeRecipient(id){ }); } +function checkCase(){ + if(document.getElementById('email_address').value.match('[A-Z]')){ + toastNotify("Votre e-mail comporte une lettre majuscule, il s'agit probablement d'une erreur."); + } +} + function sendTestEmail(id){ const admin_form = document.querySelector('.admin_form'); const test_email_success = document.querySelector('.test_email_success'); @@ -61,15 +67,21 @@ function sendTestEmail(id){ } function sendVisitorEmail(id){ - const send_email_success = document.querySelector('.send_email_success'); - send_email_success.innerHTML = 'Envoi en cours, veuillez patienter'; - send_email_success.style.backgroundColor = 'yellow'; - 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; + const send_email_success = document.querySelector('.send_email_success'); + + if(email_name === '' || email_address === '' || email_message === '' || email_captcha === ''){ + toastNotify('Veuillez remplir tous les champs.'); + return; + } + else{ + send_email_success.innerHTML = 'Envoi en cours, veuillez patienter'; + send_email_success.style.backgroundColor = 'yellow'; + } fetch('index.php?action=send_email', { method: 'POST', @@ -90,7 +102,7 @@ function sendVisitorEmail(id){ let message; let color; if(data.success){ - message = 'Votre E-mail a été envoyé!'; + message = 'Votre e-mail a été envoyé!'; color = 'lawngreen'; } else{ @@ -98,8 +110,8 @@ function sendVisitorEmail(id){ color = "orangered" } send_email_success.innerHTML = message; - toastNotify(message); send_email_success.style.backgroundColor = color; + toastNotify(message); }) .catch(error => { console.error('Erreur:', error); -- cgit v1.2.3