$(document).ready(function(){
$(".navbar a, footer a[href='#home']").on('click', function(event) {
if (this.hash !== "") {
event.preventDefault();
var hash = this.hash;
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 400, function(){
window.location.hash = hash;
});
}
if($(window).width() < 768) $(".navbar-collapse").collapse('hide');
});
$('form').on('submit', function (e) {
$('.form-group').removeClass('has-error'); // remove the error class
$('.help-block').remove();
$('.alert.alert-success').remove();
var formData = $(this).serialize();
// process the form
$.ajax({
type : 'POST',
url : '/controller.php',
data : formData + "&cli=1931",
dataType : 'json',
encode : true
}).done(function(data) {
// log data to the console so we can see
console.log(data);
// here we will handle errors and validation messages
var errore;
if (!data.success) {
errore ="attenzione è stato commesso uno o più errori: ";
// handle errors for email ---------------
if (data.errors.email) {
$('#'+ data.type+'_email-group').addClass('has-error');
errore += "\n"+data.errors.email;
}
// handle errors for name ---------------
if (data.errors.firstname) {
$('#'+ data.type+'_firstname-group').addClass('has-error');
errore += "\n"+data.errors.firstname;
}
// handle errors for lastname ---------------
if (data.errors.lastname) {
$('#'+ data.type+'_lastname-group').addClass('has-error');
errore += "\n"+data.errors.lastname;
}
// handle errors for sex ---------------
if (data.errors.sex) {
errore += "\n"+data.errors.sex;
}
alert(errore);
} else {
$('input[type=text], textarea').val('');
$('input[type=email]').val('');
$('input[type=radio]').prop("checked", false);
$('input[type=checkbox]').prop("checked", false);
// just show the success message!
$('#'+ data.type).append('' + data.message + '
');
}
});
e.preventDefault();
});
})