function formAction(elem)
{
    event.preventDefault();
    var action = $(elem).attr('action');
    var method = $(elem).attr('method');
    var submitBtn = $(elem).find('button[type="submit"]');
    
    if ($(elem).hasClass('load-submit-btn')) {
        submitBtn.prop('disabled', true);
    }

    if(method == 'GET')
    {
        var dataform = $(elem).serialize();
    }
    else
    {
        var dataform = new FormData( $(elem)[0]);
    }

    $.ajax
    ({
        url : action,
        type: method,
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        data: dataform,
        dataType:'json',
        contentType: false,
        processData: false,
        success:function(data)
        {
            if('data' in data)
            {
                toasterSuccess(data.message);
                setTimeout(
                    function()
                    {
                        window.location.href = data.data
                    }, 1000);
            }
            else
            {
                if (typeof data.errors == 'object')
                {
                    toasterError(Object.values(data.errors)[0]);
                }
                else
                {
                    toasterError(data.errors);
                }
            }
        }
        ,error:function(data)
        {
            if (typeof data.responseJSON.errors == 'object')
            {
                toasterError(Object.values(data.responseJSON.errors)[0]);
            }
            else
            {
                toasterError(data.responseJSON.errors);
            }
        },
        complete: function() {
            if ($(elem).hasClass('load-submit-btn')) {
                submitBtn.prop('disabled', false);
            }
        }
    })
}


