$(function() { $("#frmOggetto").submit( function() { if( fCheckObbligatori() ) fSaveData(); return false; }); $('#privacy').change(function() { if ( $(this).prop('checked') ) $('#lblprivacy').html( '' ); else $('#lblprivacy').html( fHTMLErrore( "Accettazione obbligatoria." ) ); }); }); function fSaveData() { fLoading(1); $('submit').focus(); $('#submitBut').addClass('d-none'); $('#submitLoad').removeClass('d-none'); var data; var strDestination = ''; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/sendSubscription.php", data: $("#frmOggetto").serialize(), success: function(data) { if ( data.status == 'ok' ) strDestination = data.destination; else swal("Oops...", "Registrazione non riuscita.", "error"); }, error: function(data) { swal("Oops...", "Procedura non completata.", "error"); } }); if ( strDestination != '' ) { location.href = strDestination; } else { $('#submitLoad').addClass('d-none'); $('#submitBut').removeClass('d-none'); fLoading(0); } } // Controllo campi obbligatori function fCheckObbligatori() { var blnReturn = true; $('submit').focus(); $('#submitBut').addClass('d-none'); $('#submitLoad').removeClass('d-none'); $('input, textarea, select').removeClass('is-invalid'); $(".lbl").html(""); var strID_Contatto = ( $('#id_cliente').length ? $('#id_cliente').val() : '' ); $('.required').each(function() { if ( $.trim( $(this).val() ) == "" ) { blnReturn = false; $(this).addClass('is-invalid'); } else { if ( $(this).attr('name') == 'txtEmail' ) { if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val()))) { blnReturn = false; $(this).addClass('is-invalid'); } } } console.log('1 - '+(blnReturn?1:0) + ' : ' + $(this).attr('id')); }); // Controllo password if ( $('#txtPassword').val() != '' || $('#txtConfermaPassword').val() != '' ) { if ( $('#txtPassword').val() != $('#txtConfermaPassword').val() ) { blnReturn = false; $('#lbltxtConfermaPassword').html( fHTMLErrore( "La password non è uguale." ) ); $('#txtConfermaPassword').addClass('is-invalid'); } else { $('#lbltxtConfermaPassword').html(""); } } // Controllo Email if ( $('#txtEmail').val() != '' ) { var data; var intExists = 0; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/checkContatto.php", data: "action=checkEmail&pstrEmail=" + $('#txtEmail').val() + "&pstrID_Contatto=" +strID_Contatto, success: function(data) { intExists = data.email_exists; if ( data.status == 'ok' ) { if ( intExists == 1 ) { // ERRORE : email non unica blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "L'indirizzo risulta già registrato al sito" ) ); $('#txtEmail').addClass('is-invalid'); } else { // OK : Email unica } } else swal("Oops...", "Verifica non riuscita.", "error"); }, error: function(data) { swal("Oops...", "Procedura non completata.", "error"); } }); } if ( ! $('#privacy').prop('checked') ) { blnReturn = false; $('#lblprivacy').html( fHTMLErrore( "Accettazione obbligatoria." ) ); } if ( ! checkRecaptcha() ) { blnReturn = false; $('#lblrecaptcha').html( fHTMLErrore( "Esegui la verifica" ) ); } $('#submitLoad').addClass('d-none'); $('#submitBut').removeClass('d-none'); return blnReturn; } function fHTMLErrore( pstr ) { return '' + pstr + ''; }