$(document).on('click', '#login', function () {
    let forms = $('.loginForm');
    let fields = ['email', 'password'];
    let isValid = true;
    forms.each(function () {
        if (!this.checkValidity()) {
            isValid = false;
            fields.forEach(field => {
                let value = $(`#${field}`).val();
                (value == '') ? $(`#${field}`).addClass('is-invalid') : $(`#${field}`).removeClass('is-invalid');
            });
        }
    });
    if (isValid) {
        const data = {
            email: $("#email").val(),
            password: $("#password").val(),
            requestType: 'login'
        };
        $('#login').attr('disabled', true).text('Please wait....');
        $.post('/adminpanel/datafiles/action.php', data, function (response) {
            var result = JSON.parse(response);
            $('#login').attr('disabled', false).text('Sign in');
            if (result.status == 1) {
                window.location.href = '/adminpanel';
            } else {
                $("#invalidError").removeClass("d-none").text(`${result.message}`);
            }
        });
    }
})