$(function() { $("#frmContacts").submit( function() { if( fCheckObbligatori() ) fSaveData(); return false; }); key('ctrl+n', function() { $('#frmContacts textarea').lorem({ type: 'paragraphs',amount:'4',ptags:false}); $('#frmContacts input[type=checkbox]').attr('checked',true); $('#txtNominativo').val('Lorem Ipsum'); $('#txtCitta').val('Lorem ipsum dolor sit amet'); $('#txtTelefono').val('+39 000 00000000'); $('#txtEmail').val('info@dynform.it'); //fCheckObbligatori( 1 ); }); key('ctrl+k', function() { $('#frmContacts input[type!=submit]').val(''); $('#frmContacts textarea').html(''); $('#frmContacts input[type=checkbox]').attr('checked',false); //fCheckObbligatori( 1 ); }); $('#txtNominativo').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/sendContatti.php", data: $("#frmContacts").serialize(), success: function(data) { strDestination = data.destination; if ( data.status == 'ok' ) blnSaved = true; else swal("Ops...", "Registrazione dati non riuscita", "error"); }, error: function(data) { swal("Ops...", "", "error"); } }); 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() != '' ) { $('#loader-email').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 swal("Ops...", "Verifica non riuscita", "error"); }, error: function(data) { swal("Ops...", "", "error"); } }); } if ( ! blnReturn ) { $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); } $('#loader-email').addClass('hide'); return blnReturn; } function fHTMLErrore( pstr ) { return '' + pstr + ''; }