-
-
Save entexa/769df606d6c9bc738d0e73af22d475f8 to your computer and use it in GitHub Desktop.
Recaptcha Example using Laravel, Blade Components, and Alpine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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