$(function() { $('#dynck').val( Math.floor(Math.random()*11111111) ); $("#frmCommento").submit( function() { $('#submitResultCommento').addClass('hide'); if ( fCheckObbligatoriCommento() ) fSaveDataCommento(); return false; }); }); function fSaveDataCommento() { $('#submitButCommento button').focus(); $('#submitButCommento').addClass('hide'); $('#submitLoadCommento').removeClass('hide'); $('#submitResultCommento').addClass('hide'); var data; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/new/assets/ajax/sendCommento.php", data: $("#frmCommento").serialize(), success: function(data) { if ( data.status == 'ok' ) { blnSaved = ( data.errore == '' ); } }, error: function(data) { alert("Il server è impegnato. Riprova più tardi per favore."); } }); if ( blnSaved ) { $('#txtCommento').val(''); $('#submitResultCommento').removeClass('hide'); } $('#submitLoadCommento').addClass('hide'); $('#submitButCommento').removeClass('hide'); } // Controllo campi obbligatori function fCheckObbligatoriCommento() { var blnReturn = true; $('#submitResultCommento').addClass('hide'); $( ".form-group" ).removeClass( "has-error" ); $( ".lbl" ).html(""); if ( $.trim( $('#txtCommento').val() ) == "" ) { blnReturn = false; $( "#lbltxtCommento" ).html( fHTMLErrore( "Campo obbligatorio" ) ); $( ".fg-txtCommento" ).addClass( "has-error" ); $('#txtCommento').focus(); } if ( $.trim( $('#txtEmail').val() ) == "" ) { blnReturn = false; $( "#lbltxtEmail" ).html( fHTMLErrore( "Campo obbligatorio" ) ); $( ".fg-txtEmail" ).addClass( "has-error" ); $('#txtEmail').focus(); } if ( $.trim( $('#txtNome').val() ) == "" ) { blnReturn = false; $( "#lbltxtNome" ).html( fHTMLErrore( "Campo obbligatorio" ) ); $( ".fg-txtNome" ).addClass( "has-error" ); $('#txtNome').focus(); } // Controllo privacy if ( ! $('#privacy').prop('checked') ) { blnReturn = false; $('#lblprivacy').html( fHTMLErrore( "Accettazione obbligatoria." ) ); $( ".fg-privacy" ).addClass( "has-error" ); } if ( ! blnReturn ) { $('#submitLoadCommento').addClass('hide'); $('#submitButCommento').removeClass('hide'); } return blnReturn; } function fHTMLErrore( pstr ) { return '' + pstr + ''; }