-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
74 lines (58 loc) · 2.58 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
<html>
<head>
<title>Google recapcha v3 demo</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css">
<script src="https://www.google.com/recaptcha/api.js?render=6LfO0JsUAAAAAGXQIrOsKj9aC7kJWBvmrkxqCNdo"></script>
<script>
grecaptcha.ready(function () {
console.log("Captcha ready");
var form = document.querySelector(".myForm");
form.addEventListener("submit", function(e){
e.preventDefault();
grecaptcha.execute('6LfO0JsUAAAAAGXQIrOsKj9aC7kJWBvmrkxqCNdo', { action: 'contact' }).then(function (token) {
console.log("Captcha executing ...");
//var recaptchaResponse = document.getElementById('recaptchaResponse');
//recaptchaResponse.value = token;
fetch('backend.php?action=examples/contact&recaptcha_response='+token).then(function(response) {
console.log("Fetch the backend ");
response.json().then(function(data) {
console.log("Captcha returning data");
console.log(data);
if(data.success) {
console.log("Success ! Submitting form in 3 seconds ...");
setTimeout(function(){
form.submit();
}, 3000);
}
}).catch(function(){
console.log("Captcha error, no response");
});
});
});
});
});
</script>
</head>
<body>
<section class="section">
<div class="container">
<div class="columns">
<div class="column is-half">
<form class="myForm">
<h3 class="title">
reCAPTCHA v3 example
</h3>
<p>Check the console for info</p>
<br />
<div class="field is-grouped">
<div class="control">
<button type="submit" class="button is-link">Get CAPTCHA Score</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
</body>
</html>