-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom-scripts.js
74 lines (51 loc) · 1.72 KB
/
custom-scripts.js
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
//Includes
//<script src='https://www.google.com/recaptcha/api.js'></script>
//reCaptcha callback function
function recaptcha_callback(){
var g_recaptcha_key = $("#g-recaptcha-response").val();
var g_recaptcha_s_key = $("#s-id").val();
var url = location.hostname;
$.post(
//Set the path if it's different
"/extensions/recaptcha/content/reCaptcha.php",
{
recaptcharesponse: g_recaptcha_key,
s_key: g_recaptcha_s_key
},
function(data) {
if(data ==="success"){
//Do validation,form submit
$("#g-recaptcha-data").val(1);
$('#g-re-cp-error').hide();
}else{
alert('Somthing went wrong');
}
}
);
}
//reCaptcha form validations (optionals)
$( document ).ready(function() {
//Register form
$('#g-re-cp-error').hide();
$("#register").submit(function(e) {
if(1) {
var value = $('#g-recaptcha-data').val();
if(value == "1"){
//alert("submit");
}else{
e.preventDefault();
//alert('test');
$('#g-re-cp-error').css("display", "block");
$('#g-re-cp-error').removeClass("hide");
$('#g-re-cp-error').text("reCAPTCHA field is required.");
}
} else {
//do some error handling
}
});
});
// Add this div set to form ..........................................
// <div class="g-recaptcha" data-callback="recaptcha_callback" data-sitekey="{$recaptcha-sitekey}"></div>
// <input id="s-id" type="hidden" value="{$recaptcha-secret-id}" />
// <input id="g-recaptcha-data" name="fields[recaptcha]" type="hidden" value="" />
// <label id="g-re-cp-error" class="error_re hide">This field is required.</label>