Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,27 @@ Meteor.methods({
return true;
}
});
```
```
### Using a Callback

You can take advantage of the `data-callback` attribute to fire a function when the reCaptcha has been completed successfully and the checkbox has been checked. This is advantageous if you don't want to rely on a submit/click event in order to trigger processing of the reCaptcha.

```
// client.html
<template name="myPage">
{{> reCAPTCHA callback="myCallback"}}
</template>

// client.js
Template.myPage.onCreated(function() {
myCallback = function () {
let captchaData = grecaptcha.getResponse();
Meteor.call('captchaCheck', captchaData, function (err, res) {
if (err) {
// Do something when the reCaptcha has failed.
} else {
// Do something when the reCaptcha has been completed successfully.
}
});
};
});
4 changes: 2 additions & 2 deletions client/client.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<template name="reCAPTCHA">
<div class="g-recaptcha" data-sitekey="{{sitekey}}"></div>
</template>
<div class="g-recaptcha" data-sitekey="{{sitekey}}" data-callback="{{callback}}"></div>
</template>
4 changes: 2 additions & 2 deletions client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Template.reCAPTCHA.helpers({
}
});

Template.reCAPTCHA.created = function () {
Template.reCAPTCHA.onCreated(function () {
if ('hl' in reCAPTCHA.settings) {
$.getScript('https://www.google.com/recaptcha/api.js?hl=' + reCAPTCHA.settings.hl);
} else {
$.getScript('https://www.google.com/recaptcha/api.js');
}
}
});
3 changes: 2 additions & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Package.onUse(function(api) {
api.use([
'templating',
'handlebars',
'ejson',
], 'client');
api.use([
'http',
Expand All @@ -20,4 +21,4 @@ Package.onUse(function(api) {
api.addFiles(['server/server.js'], 'server');
api.addFiles(['client/client.html', 'client/client.js'], 'client');
api.export && api.export('reCAPTCHA', ['client', 'server']);
});
});