Skip to content

Instantly share code, notes, and snippets.

@sudiptpa
Forked from JeffreyWay/recaptcha.blade.php
Created August 8, 2020 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudiptpa/156566b9ffea392374945ecde9876843 to your computer and use it in GitHub Desktop.
Save sudiptpa/156566b9ffea392374945ecde9876843 to your computer and use it in GitHub Desktop.
Recaptcha Example using Laravel, Blade Components, and Alpine
<div
x-data="recaptcha()"
x-init="init"
@recaptcha.window="execute"
></div>
@push('scripts')
<script src="https://www.google.com/recaptcha/api.js?render=explicit"></script>
<script>
window.recaptcha = () => {
return {
init() {
grecaptcha.ready(() => {
grecaptcha.render(this.$el, {
sitekey: '{{ config('services.recaptcha.key') }}',
size: 'invisible',
callback: this.onComplete.bind(this)
});
});
},
execute() {
grecaptcha.execute();
},
onComplete() {
this.$el.closest('form').submit();
}
};
};
</script>
@endpush
<form method="POST"
x-data
@submit.prevent="$dispatch('recaptcha')"
>
@csrf
<!-- Your form inputs -->
<x-recaptcha />
<button type="submit">Submit</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment