-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
129 lines (102 loc) · 4.17 KB
/
index.html
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html>
<head>
<title>Test Form</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<div class="container">
<h1>Test Form</h1>
<form id="contactForm" method="post" action="process.php" class="contact-form">
<div class="alert alert-danger display-error" style="display: none">
</div>
<div class="form-group">
<div class="controls">
<input type="text" id="contact_firstname" class="form-control" name="name" placeholder="Name">
<div id="name-warning"></div>
</div>
</div>
<div class="form-group">
<div class="controls">
<input type="email" class="email form-control" id="email" name="email" placeholder="Email">
<div id="email-warning"></div>
</div>
</div>
<div class="form-group">
<div class="controls">
<input type="text" id="msg_subject" class="form-control" name="msg_subject" placeholder="Subject">
<div id="subject-warning"></div>
</div>
</div>
<div class="form-group">
<div class="controls">
<textarea id="message" rows="7" name="msg_text" placeholder="Message" class="form-control"></textarea>
<div id="message-warning"></div>
</div>
</div>
<button type="submit" id="submit" class="btn btn-success g-recaptcha" name="submit" data-sitekey="ENTER SITEKEY HERE"
data-callback="submitForm" data-size="invisible">
<i class="fa fa-check"></i> Send Message</button>
<div id="captcha-warning"></div>
</form>
<div id="form-message" style="margin-top: 20px;"></div>
</div>
</body>
<script type="text/javascript">
$(document).ready(function() {
$('#contactForm').submit(function(e){
e.preventDefault();
});
});
function submitForm(token) {
grecaptcha.execute();
var name = $("#contact_firstname").val();
var email = $("#email").val();
var msg_subject = $("#msg_subject").val();
var msg_text = $("#message").val();
var recaptcha = token;
$.ajax({
type: "POST",
url: "process.php",
dataType: "json",
data: {name:name, email:email, msg_subject:msg_subject, msg_text:msg_text, grecaptcha:recaptcha},
}).done(function(data){
if (!data.success) {
if (data.errors.name) {
$('#name-warning').html('<div class="help-block input-alert-error">' + data.errors.name + '</div>');
} else {
$('#name-warning').html('');
}
if (data.errors.email) {
$('#email-warning').html('<div class="help-block input-alert-error">' + data.errors.email + '</div>');
} else {
$('#email-warning').html('');
}
if (data.errors.msg_subject) {
$('#subject-warning').html('<div class="help-block input-alert-error">' + data.errors.msg_subject + '</div>');
} else {
$('#subject-warning').html('');
}
if (data.errors.msg_text) {
$('#message-warning').html('<div class="help-block input-alert-error">' + data.errors.msg_text + '</div>');
} else {
$('#message-warning').html('');
}
if (data.errors.grecaptcha) {
$('#message-warning').html('<div class="help-block input-alert-error">' + data.errors.grecaptcha + '</div>');
} else {
$('#captcha-warning').html('');
}
$('#form-message').html('<div class="alert alert-danger">' + data.message + '</div>');
} else {
$('.help-block').remove();
$('#form-message').html('<div class="alert alert-success">' + data.message + '</div>');
$('#contactForm').trigger("reset");
}
grecaptcha.reset();
});
}
</script>
</html>