forked from stevenmills/bootstrapvalidator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecaptcha.html
93 lines (85 loc) · 3.5 KB
/
recaptcha.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
<!DOCTYPE html>
<html>
<head>
<title>ReCaptcha demo</title>
<link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
<link rel="stylesheet" href="../dist/css/formValidation.css"/>
<script type="text/javascript" src="../vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../dist/js/formValidation.js"></script>
<script type="text/javascript" src="../dist/js/framework/bootstrap.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<div class="page-header">
<h1>ReCaptcha demo</h1>
</div>
<form id="defaultForm" method="post" class="form-horizontal" action="target.php">
<div class="form-group">
<label class="col-sm-3 control-label">Captcha</label>
<div class="col-sm-9 captchaContainer">
<div id="recaptcha"></div>
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// Replace "6Ld6bP0SAAAAAJ8Hv9NOf85OulTX0C_1vPKf_7XH" with your public key
Recaptcha.create('6Ld6bP0SAAAAAJ8Hv9NOf85OulTX0C_1vPKf_7XH', 'recaptcha', {
theme: 'white',
callback: captchaLoaded
});
function captchaLoaded() {
$('#defaultForm')
.on('added.field.fv', function(e, data) {
// The field "recaptcha_response_field" has just been added
if (data.field === 'recaptcha_response_field') {
// Find the icon
var $parent = data.element.parents('.form-group'),
$icon = $parent.find('.form-control-feedback[data-fv-icon-for="' + data.field + '"]');
// Move icon to other position
$icon.insertAfter('#recaptcha');
}
})
// Add new field after loading captcha
.formValidation('addField', 'recaptcha_response_field', {
validators: {
notEmpty: {
message: 'The captcha is required and can\'t be empty'
},
remote: {
type: 'POST',
url: 'recaptcha.php',
message: 'The captcha is not valid',
data: function() {
return {
recaptcha_challenge_field: $('#defaultForm').find('[name="recaptcha_challenge_field"]').val()
};
},
delay: 1000
}
}
});
};
$('#defaultForm').formValidation({
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
}
});
});
</script>
</body>
</html>