HOME


Mini Shell 1.0
DIR: /home/islapiiu/sites/royalescapestours/assets/js/
Upload File :
Current File : /home/islapiiu/sites/royalescapestours/assets/js/create-guest-comment.js
$(document).ready(function () {

    jQuery("#txtFullName").blur(function () {
        validateEmpty("txtFullName", "spanFullName");
    });

    jQuery("#txtCountry").blur(function () {
        validateEmpty("txtCountry", "spanCountry");
    });

    jQuery("#txtprofileimg").blur(function () {
        validateEmpty("txtprofileimg", "spanprofileimg");
    });


    jQuery("#captchacode").blur(function () {
        validateEmpty("captchacode", "capspan");
    });


    $('#btnSubmit').click(function (e) {

        e.preventDefault();
        if (!validate()) {
            return;
        }

        jQuery("#checking").show();


        var formData = new FormData($('#guestcomment')[0]);

        $.ajax({
            url: "ajax/create-guest-comment.php",
            type: "POST",
            data: formData,
            async: false,
            dataType: 'json',
            success: function (mess)
            {
                swal({
                    title: "Success",
                    text: "Your comment has been posted successful.",
                    type: 'success',
                    timer: 2000,
                    showConfirmButton: false

                });


                setTimeout(function () {
                    location.reload();
                }, 1000);




            },
            cache: false,
            contentType: false,
            processData: false
        });

    });
});
function validate() {

    if (
            validateEmpty("txtFullName", "spanFullName") &
            validateEmpty("txtCountry", "spanCountry") &
            validateEmpty("txtprofileimg", "spanprofileimg") &
            validateEmpty("captchacode", "capspan")

            )
    {
        return true;
    } else {

        return false;
    }
}

function validateEmpty(field, validatorspan)

{
    
    if (jQuery('#' + field).val().length != 0)
    {
        
        jQuery('#' + validatorspan).addClass("validated");
        jQuery('#' + validatorspan).removeClass("notvalidated");
        jQuery('#' + validatorspan).fadeIn('slow').fadeOut(3000);
        jQuery('#' + validatorspan).text("");

        return true;
    } else
    {
        
        jQuery('#' + validatorspan).addClass("notvalidated");
        jQuery('#' + validatorspan).removeClass("validated");
        jQuery('#' + validatorspan).fadeIn('slow').fadeOut(3000);
        jQuery('#' + validatorspan).text("This field can not be empty");

        return false;
    }
}