$(function() { $('[data-remodal-id=avviso]').remodal().open(); $("#frmRichiedi").submit( function() { if( fCheckObbligatori() ) fSaveData(); return false; }); $('#txtRagioneSociale').focus(); }); function fSaveData() { $('submit').focus(); $('#submitBut').addClass('hide'); $('#submitLoad').removeClass('hide'); var data; var strDestination = ''; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/sendRichiediContatto.php", data: $("#frmRichiedi").serialize(), success: function(data) { strDestination = data.destination; if ( data.status == 'ok' ) blnSaved = true; else alert("Registrazione dati non riuscita"); }, error: function(data) { alert("Procedura non completata."); } }); if ( blnSaved ) { location.href = strDestination; } else { $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); } } // Controllo campi obbligatori function fCheckObbligatori() { var blnReturn = true; $( ".form-group" ).removeClass( "has-error" ); $( ".lbl" ).html(""); $('.required').each(function() { if ( $.trim( $(this).val() ) == "" ) { blnReturn = false; $( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "Campo obbligatorio" ) ); $( ".fg-" + $(this).attr("name") ).addClass( "has-error" ); } }); // Controllo privacy if ( ! $('#privacy').prop('checked') ) { blnReturn = false; $('#lblprivacy').html( fHTMLErrore( "Accettazione obbligatoria." ) ); $( ".fg-privacy" ).addClass( "has-error" ); } // Controllo Email if ( $('#txtEmail').val() != '' ) { $('#email-loader').removeClass('hide'); $('#lbltxtEmail').html(''); var intErrore = ''; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/checkEmail.php", data: "action=checkEmail&pstrEmail=" + $("#txtEmail").val(), success: function(data) { intErrore = data.errore; if ( intErrore == 1 ) { // ERRORE : email NON corretta blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "L'indirizzo non รจ corretto." ) ); $( ".fg-txtEmail" ).addClass( "has-error" ); } else if ( intErrore == 2 ) { // ERRORE : email NON esiste blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "L'indirizzo non esiste" ) ); $( ".fg-txtEmail" ).addClass( "has-error" ); } if ( data.status == 'errore' ) blnSaved = false; else if ( data.status == 'ok' ) blnSaved = true; else alert("Verifica non riuscita"); }, error: function(data) { alert("Procedura non completata."); } }); $('#email-loader').addClass('hide'); } if ( ! blnReturn ) { $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); } return blnReturn; } function fHTMLErrore( pstr ) { return '' + pstr + ''; }