function Envoyer(nom_form) { //alert(nom_form); var Form = window.document.forms[nom_form]; if (Form.champs_obligatoires) { var champs = Form.champs_obligatoires.value; var aChamps = champs.split('#'); //alert(aChamps); var bError,szError; bError = false; szError = 'Votre message ne peut être envoyé.\nVous avez oublié de remplir les champs suivants :'; for (i = 0; i < aChamps.length; i ++ ) { if(Form[aChamps[i]] && (!Form[aChamps[i]].value && !(Form[aChamps[i]].checked == true) ) ) { bError = true; szError = szError + '\n - ' + aChamps[i]; } } if(bError == true) { alert(szError); } else { $.ajax({ type: 'POST', url: '/commun/modeles/commun/javascript/scripts/form_envoi.php', dataType: 'html', data: $(Form).serialize(), success: function(oReponseJSON){ ga('send', 'event', 'contact', 'envoie'); alert('Votre message a bien été envoyé'); $('input[type="tel"]').val(''); $('input[type="text"]').val(''); $('input[type="email"]').val(''); $('textarea').val(''); $('input[type="checkbox"]').removeAttr('checked'); } }); } } else { $.ajax({ type: 'POST', url: '/commun/modeles/commun/javascript/scripts/form_envoi.php', dataType: 'html', data: $(Form).serialize(), success: function(oReponseJSON){ ga('send', 'event', 'contact', 'envoie'); alert('Votre message a bien été envoyé'); $('input[type="tel"]').val(''); $('input[type="text"]').val(''); $('input[type="email"]').val(''); $('textarea').val(''); $('input[type="checkbox"]').removeAttr('checked'); } }); } }