HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/immoginis.komma.pro/wwwroot/js/houseHuntersForm.js
/**
 * Created by Pascal on 13/04/16.
 */
$(function () {


    $('#houseHuntersForm #sendButton').click(function () {

        var send = true;

        var sendValue = {
            name: $('#houseHuntersForm #name').val(),
            sur_name: $('#houseHuntersForm #sur_name').val(),
            email: $('#houseHuntersForm #email').val(),
            phone: $('#houseHuntersForm #phone').val(),

            extra_message: $('#houseHuntersForm #extra_message').val(),

            bedrooms: $('#houseHuntersForm #bedrooms').val(),
            min_op: $('#houseHuntersForm #min_op').val(),
            max_op: $('#houseHuntersForm #max_op').val(),
            min_price: $('#houseHuntersForm #min_price').val(),
            max_price: $('#houseHuntersForm #max_price').val(),

            secretCode: 'isHuman'
        };
        $('.check-alert').removeClass('show');
        $('.input-rows .alert, #typeCheckboxes .notification.alert, .region-search .notification.normal').removeClass('alert');
        $('.check-alert.temp').remove();


        let typesString = '';

        // Check for the type chechboxes
        $('#typeCheckboxes .type_checkbox:checked').each(function () {
            typesString += $(this).val() + ',';
        }) ;

        if(typesString === '') {
            send = false;
            $('#typeCheckboxes .notification').addClass('alert');
        }
        else typesString = typesString.substring(0, typesString.length - 1);

        sendValue.types = typesString;


        let regions = '';

        $('#js-region-list .region-list__item').each(function () {
            regions += $(this).html() + ',';
        });

        if(regions === '') {
            send = false;
            $('.region-search .notification.normal').addClass('alert');
        }
        else regions = regions.substring(0, regions.length - 1);

        sendValue.region = regions;

        if (sendValue.name == '') {
            send = false;
            $('#houseHuntersForm #name').addClass('alert');
        }
        if (sendValue.sur_name == '') {
            send = false;
            $('#houseHuntersForm #sur_name').addClass('alert');
        }
        if (sendValue.email == '') {
            send = false;
            $('#houseHuntersForm #email').addClass('alert');
        }
        if (sendValue.phone == '') {
            send = false;
            $('#houseHuntersForm #phone').addClass('alert');
        }

        if (sendValue.min_price == '') {
            send = false;
            $('#houseHuntersForm #min_price').addClass('alert');
        }

        if (sendValue.max_price == '') {
            send = false;
            $('#houseHuntersForm #max_price').addClass('alert');
        }

        // if (sendValue.extra_message == '') {
        //     send = false;
        //     $('#houseHuntersForm #extra_message').addClass('alert');
        // }

        if (send) {
            $.ajax({
                method: "POST",
                data: sendValue,
                url: $('#houseHuntersForm').attr('action')
            }).done(function (msg) {
                console.log(msg);

                $errorHtml = '';

                if (msg != 'true') {

                    msg.forEach(function(element) {
                        $errorHtml += '<p class="notification alert">' + element + '</p>';
                    });

                    $('#houseHuntersForm .error-area').html($errorHtml);

                }
                else {
                    $('#houseHuntersForm .error-area').innerHTML = '';
                    $('#sendButton').remove();
                    $('#houseHuntersForm').remove();
                    $('.thanks').show();
                }
            });
        }
        else {
            $([document.documentElement, document.body]).animate({
                scrollTop: $(".input-rows .alert, #typeCheckboxes .notification.alert, .region-search .notification.normal").offset().top - 230
            }, 600);
        }

    });
});