Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invisible recaptcha + webpack + live form #28

Closed
martinjinda opened this issue Jun 14, 2019 · 8 comments
Closed

Invisible recaptcha + webpack + live form #28

martinjinda opened this issue Jun 14, 2019 · 8 comments

Comments

@martinjinda
Copy link

martinjinda commented Jun 14, 2019

Hello guys, we want to use invisible reCaptcha, since the regular one is working perfectly. But we got following error from the compiled js script Nette is not defined.

Screenshot 2019-06-14 at 12 29 38

If I use the script the included directly in main.js with window.Nette or $.nette the form is sent but we don't get any response from Nette. We also have the form included in the snippet (#12).

main.js compiled with webpack

import 'recaptcha.invisible.js';

require('nette.ajax.js');

window.Nette = require('live-form-validation');
window.Nette.initOnLoad();

$.nette.init();
$.nette.ext('unique');

We have (but I tested with Nette 3.0 + reCaptcha 3.2 and it was the same problem).

  • Nette 2.4
  • contributte/recaptcha 3.1.0
  • PHP 7.2

Has anyone run into the same problem? Thank you

@f3l1x
Copy link
Member

f3l1x commented Jun 15, 2019

Hi. Unfortunately I don't know. Maybe others.

@JanGalek
Copy link
Contributor

Hi, I'll look at it this week ;)

@spulakk
Copy link

spulakk commented Nov 20, 2019

Hello, any news on this issue? I'm getting the same error.

Same Nette and ReCaptcha version, PHP 7.1

@JanGalek
Copy link
Contributor

I investigated, Have you added https://nette.github.io/resources/js/3/netteForms.min.js too ?

ping @martinjinda @spulakk

@JanGalek
Copy link
Contributor

Problem is that it create anonym function so invisibleRecaptcha dont know about this var. I tried add

window.Nette = require('live-form-validation');
window.Nette.initOnLoad();

into invisibleRecaptcha.js and it works.

@spulakk
Copy link

spulakk commented Nov 21, 2019

I tried adding the snippet at the start of invisibleRecaptcha.js and it didn't change anything for me. Also I was fairly time constrained so I went with my own implementation of ReCaptcha already. Thanks for trying though, hopefully it helps @martinjinda at least.

@JanGalek
Copy link
Contributor

JanGalek commented Nov 21, 2019

@spulakk ok :)

Problem solved with configuration webpack

ebpack.config.js:

const path = require('path');
const webpack = require('webpack');

module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'main.js',
        path: path.resolve(__dirname, 'www'),
    },
    plugins: [
        new webpack.ProvidePlugin({
            Nette: 'live-form-validation'
        }),
    ],
};

of course remove require of live-form-validation

my index.js

Nette.initOnLoad();
import './invisibleRecaptcha'

documentation: https://webpack.js.org/guides/shimming/#shimming-globals

@martinjinda
Copy link
Author

Thanks @JanGalek. It's great, we start using live-form-validation-es6 so you don't have to provide plugin in webpack config. And it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants