-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
113 lines (106 loc) · 4.81 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
<!DOCTYPE HTML>
<html lang="el">
<head>
<title>Ajax PHPMailer ReCaptcha3 JQueryValidate Form</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<meta name="description" content="Ajax PHPMailer ReCaptcha JQueryValidate Form">
<meta name="keywords" content="contact, form, recaptcha, secure, ajax">
</head>
<body>
<article id="contact">
<header>
<h2>Ajax PHPMailer ReCaptcha3 JQueryValidate Form</h2>
</header>
<form name="frmContact" id="frmContact">
<input type="hidden" name="recaptcha_response" id="recaptchaResponse">
<div>
<div>
<div>
<input type="text" name="name" id="name" placeholder="Name" />
</div>
<div>
<input type="text" name="email" id="email" placeholder="Email" />
</div>
<div>
<input type="text" name="subject" id="subject" placeholder="Subject" />
</div>
<div>
<textarea name="message" id="message" placeholder="Message" rows="6"></textarea>
</div>
<div>
<input type="submit" name="btnContact" id="button" value="Send Message" />
</div>
<div>
<small>This site is protected by reCAPTCHA and the Google
<a href="https://policies.google.com/privacy">Privacy Policy</a> and
<a href="https://policies.google.com/terms">Terms of Service</a> apply.</small>
</div>
<div>
<small>By submitting this form you agree that your personal information will be processed by the website</small>
</div>
</div>
</div>
</form>
</article>
<!-- Scripts -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"></script>
<script async src="https://www.google.com/recaptcha/api.js?render=RECAPTCHA_KEY_GOES_HERE"></script>
<script>
$(document).ready(function() {
$("#frmContact").validate({
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
subject: {
required: true
},
message: {
required: true
}
},
messages: {},
submitHandler: function(form) {
document.getElementById("button").disabled = true;
var thankyoudiv = '<div><center><h2>Thank You!</h2></center></div>';
var errordiv = '<div><center><h2>There was an error. Please try again later</h2></center></div>';
grecaptcha.ready(function() {
grecaptcha.execute('RECAPTCHA_KEY_GOES_HERE', {
action: 'contact'
}).then(function(token) {
var recaptchaResponse = document.getElementById('recaptchaResponse');
recaptchaResponse.value = token;
var fomr = $('form')[0];
var formData = new FormData(fomr);
$.ajax({
type: 'POST',
url: "sendmail.php",
data: formData,
cache: false,
contentType: false,
processData: false,
success: function(data) {
console.log(data);
if (data.trim() == '1') {
$("#frmContact").replaceWith($(thankyoudiv));
} else {
$("#frmContact").replaceWith($(errordiv));
}
}
});
});
});
$("#frmContact").replaceWith($(errordiv));
return false;
}
});
});
</script>
</body>
</html>