function saveForm(elem)
{
    $('.butn').attr('disabled','disabled');
    event.preventDefault();
    var action = $(elem).attr('action');
    let dataform = new FormData( $(elem)[0]);
    $.ajax
    ({
        url : action,
        type: 'POST',
        data: dataform,
        dataType : 'json',
        contentType: false,
        processData: false,
        success:function(data)
        {
            $('#errors').html('');
            $('#errors').css("display", "none");
            if(data.hasOwnProperty('errors'))
            {
                 $('#errors').css("display", "block");
                let html = '<div class="alert alert-danger">';
                $.each(data.errors, function(key,value)
                {
                    html += '<li>'+value+'</li>';
                });
                html += "</div>";
                $('#errors').html(html);
                $('.butn').removeAttr('disabled','disabled');
            }
            else
            {
                setTimeout(
                    function()
                    {
                       window.location.href = data.data
                    }, 1000);
            }
        }
        ,error:function(data)
        {
            $('#errors').css("display", "block");
            $('.is-invalid').removeClass('is-invalid');
            let html = '<div class="alert alert-danger">';
            $.each(data.responseJSON.errors, function(key,value)
            {
                html += '<li>'+value+'</li>';
                $('input[name='+key+']').addClass('is-invalid');
                $('select[name='+key+']').addClass('is-invalid');
                $('textarea[name='+key+']').addClass('is-invalid');
            });
            $('.butn').removeAttr('disabled','disabled');
            html += "</div>";
            $('#errors').html(html);
        }
    })
}
