forked from ClickHouse/clickhouse-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (41 loc) · 1.52 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function serializeForm(form){
var result = {};
$.map(form.serializeArray(), function(n, i){
result[n['name']] = n['value'];
});
return result;
};
$(document).ready(function () {
var meetup_form = $('#meetup-form');
$("#meetup-form-send").on('click', function(e) {
e.preventDefault();
var valid = true;
var required_fields = $('#meetup-form input[required="true"]');
$.each(required_fields, function(idx) {
var input = $(required_fields[idx]);
if (!input.val()) {
valid = false;
input.addClass('border-danger');
} else {
input.removeClass('border-danger');
}
});
if (valid) {
var data = JSON.stringify(serializeForm(meetup_form));
$.ajax({
url: '/meet-form/',
type: 'POST',
dataType: 'json',
data: data,
success: function () {
meetup_form.html('<div class="alert alert-success mt-3"><h2>Thanks!</h2><p class="lead">We\'ll be in touch soon.</p></div>');
$('#meetup-form-error').html('');
},
error: function () {
$('#meetup-form-error').html('<div class="alert alert-danger mt-3"><strong>Error!</strong> Unfortunately it didn\'t work for some reason, please try again or use the email address below.</div>');
}
});
}
return false;
});
});