function saveForm(elem)
{
    $('.butn').attr('disabled','disabled');
    event.preventDefault();
    var action = $(elem).attr('action');
    $('.is-invalid').removeClass('is-invalid');
    let dataform = new FormData( $(elem)[0]);

    let langs = ['ar', 'en'];
    let fields = ['description','reply'];
    for (let field of fields) {
        let textareaId = `${field}`;

        if ($(`#${textareaId}`).hasClass('my-editor')) {
            let tinymceContent = tinymce.get(textareaId).getContent();
            dataform.append(textareaId, tinymceContent);
        }

        for (let lang of langs) {
            let textareaId = `${field}_${lang}`;

            if ($(`#${textareaId}`).hasClass('my-editor')) {
                let tinymceContent = tinymce.get(textareaId).getContent();
                dataform.append(textareaId, tinymceContent);
            }
        }
    }

    $.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>';
                    if (key.indexOf('.') == 0)
                    {
                        $('input[name='+key+']').addClass('is-invalid');
                        $('select[name='+key+']').addClass('is-invalid');
                        $('textarea[name='+key+']').addClass('is-invalid');
                    }
                    else
                    {
                        var keys = key.replaceAll(".","_");

                        $('#'+keys).addClass('is-invalid');
                    }
                });
                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");
            let html = '<div class="alert alert-danger">';
            $.each(data.responseJSON.errors, function(key,value)
            {
                html += '<li>'+value+'</li>';
                if (key.indexOf('.') > -1)
                {
                    var keys = key.replaceAll(".","_");

                    $('#'+keys).addClass('is-invalid');
                }
                else
                {
                    $('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);
        }
    })
}
