forked from bradtraversy/recaptchav2_node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
60 lines (53 loc) · 1.88 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M"
crossorigin="anonymous">
<script src='https://www.google.com/recaptcha/api.js'></script>
<title>Subscribe Form</title>
</head>
<body>
<div class="container">
<h1>Subscribe</h1>
<form id="subscribeForm">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" id="name" class="form-control">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" name="email" id="email" class="form-control">
</div>
<div class="form-group">
<div class="g-recaptcha" data-sitekey="6LdpvDEUAAAAAMy8x0y8PS99j4BavfO2oBdVTQGZ"></div>
</div>
<input type="submit" value="Submit" class="btn btn-primary">
</form>
</div>
<script>
document.getElementById('subscribeForm').addEventListener('submit', submitForm);
function submitForm(e){
e.preventDefault();
const name = document.querySelector('#name').value;
const email = document.querySelector('#email').value;
const captcha = document.querySelector('#g-recaptcha-response').value;
fetch('/subscribe', {
method:'POST',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-type':'application/json'
},
body:JSON.stringify({name:name, email: email, captcha: captcha})
})
.then((res) => res.json())
.then((data) => {
console.log(data);
alert(data.msg);
});
}
</script>
</body>
</html>