dimanche 24 juillet 2016

Laravel - Google reCaptcha 2 to either be not required or hidden in test environment

I am currently using the FormValidation.io package, to help validate my forms. At the moment, the reCaptcha 2 service is required for the user to "tick" it, but my automated tests are failing because of it (I can't tick it!).

I've read further into this and I can use a site key, provided by Google, to show that it's "Only for test purposes" - http://ift.tt/1MknIg5.

However, the nature of this plugin still says that it's required (see below).

captcha screenshot

How can I remove the "required" element only in my test environment, and have it required in prod.

Current code (snippet):

<script>
        $(document).ready(function () {
            $('#registrationForm').formValidation({
                framework: 'bootstrap4',
                icon: {
                    valid: 'fa fa-check',
                    invalid: 'fa fa-times',
                    validating: 'fa fa-refresh'
                },
                addOns: {
                    mandatoryIcon: {
                        icon: 'fa fa-asterisk'
                    },
                    reCaptcha2: {
                        element: 'captchaContainer',
                        language: 'en',
                        theme: 'light',
                        siteKey: '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI',
                        timeout: 120,
                        message: 'The captcha is not valid'
                    }
                },

How have you tested reCaptcha in Laravel? Many thanks.

Aucun commentaire:

Enregistrer un commentaire