PageSourceSearch

https://www.akatpension.com/js/universal-contact-form.js

js akatpension.com collected 2026-10-08 09:43:59 UTC 4,654 bytes, 117 lines download raw bytes

1$(function () {
2
3    // validation rules
4    var nameReg  = /[A-ZĚŠČŘŽÝÁÍÉa-zěščřžýáíé]+\s[A-ZĚŠČŘŽÝÁÍÉa-zěščřžýáíé]+/;
5    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})+$/;
6    var phoneReg = /^[+]?[()\/0-9. -]{9,}$/;
7
8
9    // main
10    var ContactForm = {
11        form          : $('#universal-contact-form'),
12        formData      : null,
13        $formContent  : $(this).find('#formContent'),
14        $submitBtn    : $(this).find('input[type=submit]'),
15        $success      : $(this).find('.alert-success'),
16        $failure      : $(this).find('.alert-danger'),
17        $warning      : $(this).find('.alert-warning'),
18        requiredInput : $(this).find('.required'),
19        requiredRadio : $(this).find('input[type=radio].required'),
20        requiredCheck : $(this).find('input[type=checkbox].required'),
21        validEmail    : $(this).find('input[type=email]'),
22        validFullName : $(this).find('input.full-name'),
23        validPhone    : $(this).find('input.phone'),
24        redirectUrl   : $(this).find('input[name=redirectUrl]').val(),
25
26
27        _init : function () {
28            $(this.requiredRadio).each(function () { // set "required" attr to all required radio inputs
29                $(this).prop('required', true);
30            });
31            $(this.requiredCheck).each(function () { // set "required" attr to all required checkbox inputs
32                $(this).prop('required', true);
33            });
34
35            this.form.submit(function (e) {
36                ContactForm.formData = new FormData();
37
38                e.preventDefault();
39                if (ContactForm._validate()) {
40                    ContactForm._manageData($(this).serializeArray());
41                    ContactForm.send();
42                }
43            })
44        },
45
46        _manageData : function (data) {
47            $(data).each(function () {
48                ContactForm.formData.append('values[' + $(this)[0].name + ']', $(this)[0].value);
49            });
50
51            if (this.form.find('input:file').length) {
52                this.form.find('input:file').each(function() {
53                    ContactForm.formData.append('files[]' , $(this)[0].files[0]);
54                })
55            }
56        },
57
58        _validate : function () {
59            $(this.requiredInput).each(function () { // all required inputs
60                $(this).val() == '' ? $(this).addClass("nonvalid") : $(this).removeClass("nonvalid");
61            });
62            nameReg.test(this.validFullName.val()) ? this.validFullName.removeClass("nonvalid") : this.validFullName.addClass("nonvalid");
63            emailReg.test(this.validEmail.val()) ? this.validEmail.removeClass("nonvalid") : this.validEmail.addClass("nonvalid");
64            phoneReg.test(this.validPhone.val()) ? this.validPhone.removeClass("nonvalid") : this.validPhone.addClass("nonvalid");
65
66            var valid = $(".nonvalid").length == 0 ? true : false;
67
68            if (!valid) {
69                ContactForm.$warning.show();
70            } else {
71                ContactForm.$warning.hide();
72            }
73
74            return valid;
75        },
76
77        _onChangeValidate : function () {
78            ContactForm.validFullName.change(function () {
79                nameReg.test($(this).val()) ? $(this).removeClass("nonvalid") : $(this).addClass("nonvalid");
80            });
81
82            ContactForm.validEmail.change(function () {
83                emailReg.test($(this).val()) ? $(this).removeClass("nonvalid") : $(this).addClass("nonvalid");
84            });
85
86            ContactForm.validPhone.change(function () {
87                phoneReg.test($(this).val()) ? $(this).removeClass("nonvalid") : $(this).addClass("nonvalid");
88            });
89        },
90
91        send : function () {
92            $.ajax({
93                type        : "POST",
94                url         : "/contactForm/send",
95                data        : ContactForm.formData,
96                contentType : false,
97                cache       : false,
98                processData : false,
99            }).done(function (msg) {
100                if (msg.success) {
101                    if (ContactForm.redirectUrl) {
102                        window.location.href = ContactForm.redirectUrl;
103                    } else {
104                        ContactForm.$success.fadeIn();
105                        ContactForm.$formContent.slideUp(1000);
106                        ContactForm.$submitBtn.hide();
107                    }
108                } else {
109                    ContactForm.$failure.fadeIn();
110                }
111            });
112        }
113    };
114
115    ContactForm._init();
116    ContactForm._onChangeValidate();
117});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.