barrelstrength / sprout-forms-google-recaptcha

MIT License
3 stars 5 forks source link

Installing issue with Sprout Forms 3.9.0 #16

Closed lexislav closed 4 years ago

lexislav commented 4 years ago

Description (screenshots, logs, ...)

When installing on pruduction server, I am getting error when installing plugin: Error: Class name must be a valid object or a string

When installing on local, the plugin is installed, but opening Sprout Form / Settings / Spam protection gets me an yii eroror:

yii\base\ErrorException: array_merge(): Expected parameter 1 to be an array, null given in /Users/lexislav/Websites/koma-family.cz/vendor/barrelstrength/sprout-forms-google-recaptcha/src/integrations/sproutforms/captchas/GoogleRecaptcha.php:91
Stack trace:
#0 /Users/lexislav/Websites/koma-family.cz/vendor/craftcms/cms/src/web/ErrorHandler.php(74): yii\base\ErrorHandler->handleError(2, 'array_merge(): ...', '/Users/lexislav...', 91)
#1 [internal function]: craft\web\ErrorHandler->handleError(2, 'array_merge(): ...', '/Users/lexislav...', 91, Array)
#2 /Users/lexislav/Websites/koma-family.cz/vendor/barrelstrength/sprout-forms-google-recaptcha/src/integrations/sproutforms/captchas/GoogleRecaptcha.php(91): array_merge(NULL, Array)
#3 /Users/lexislav/Websites/koma-family.cz/vendor/barrelstrength/sprout-forms-google-recaptcha/src/integrations/sproutforms/captchas/GoogleRecaptcha.php(122): barrelstrength\sproutformsgooglerecaptcha\integrations\sproutforms\captchas\GoogleRecaptcha->getSettings()
#4 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Extension/CoreExtension.php(1499): barrelstrength\sproutformsgooglerecaptcha\integrations\sproutforms\captchas\GoogleRecaptcha->getCaptchaSettingsHtml()
#5 /Users/lexislav/Websites/koma-family.cz/vendor/craftcms/cms/src/helpers/Template.php(96): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(barrelstrength\sproutformsgooglerecaptcha\integrations\sproutforms\captchas\GoogleRecaptcha), 'getCaptchaSetti...', Array, 'method', false, false)
#6 /Users/lexislav/Websites/koma-family.cz/storage/runtime/compiled_templates/85/85d69010c3f10cfd9cc5293b59261a81ad3d84db32cdf2fdfd1387b796969707.php(111): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(barrelstrength\sproutformsgooglerecaptcha\integrations\sproutforms\captchas\GoogleRecaptcha), 'getCaptchaSetti...', Array, 'method')
#7 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(407): __TwigTemplate_60517c45059729e1407545627fe7c813b873f7156fc4827afef87f9db499dfa1->doDisplay(Array, Array)
#8 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#9 /Users/lexislav/Websites/koma-family.cz/storage/runtime/compiled_templates/11/112770e1ae10c01341efe56b562866b8579470fe002efa6a7af67a6cd2222ffd.php(92): Twig\Template->display(Array)
#10 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(184): __TwigTemplate_8739459ef56725941c383f54d4413eb3560b86bcba36f77082192ae849cc1840->block_content(Array, Array)
#11 /Users/lexislav/Websites/koma-family.cz/storage/runtime/compiled_templates/6a/6a6f101327b6562dac87535b77ee6df86b1fcf5127dbf96081dafc2bd3e04319.php(411): Twig\Template->displayBlock('content', Array, Array)
#12 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(184): __TwigTemplate_78b73f3c400b8cecce86003bbfe741acf24b622cf9ad120c1458b401cb251626->block_main(Array, Array)
#13 /Users/lexislav/Websites/koma-family.cz/storage/runtime/compiled_templates/6a/6a6f101327b6562dac87535b77ee6df86b1fcf5127dbf96081dafc2bd3e04319.php(266): Twig\Template->displayBlock('main', Array, Array)
#14 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(184): __TwigTemplate_78b73f3c400b8cecce86003bbfe741acf24b622cf9ad120c1458b401cb251626->block_body(Array, Array)
#15 /Users/lexislav/Websites/koma-family.cz/storage/runtime/compiled_templates/aa/aafd9db82aa51e5e06270361db883599671dd84a7396e2a53c93663f5f5e40a0.php(75): Twig\Template->displayBlock('body', Array, Array)
#16 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(407): __TwigTemplate_5fbb6556f9a841ef56b5e36ec664a1e4925c715282b1f5edb530918ec4089d31->doDisplay(Array, Array)
#17 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#18 /Users/lexislav/Websites/koma-family.cz/storage/runtime/compiled_templates/7a/7a64533ecd6508ed44864a7c7ae567d91eb0dc150d5bb417f40a4464716ea244.php(56): Twig\Template->display(Array, Array)
#19 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(407): __TwigTemplate_49e439df691a185fa95505ad722acd0284486042cdb523e2e1d076053758bcc2->doDisplay(Array, Array)
#20 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#21 /Users/lexislav/Websites/koma-family.cz/storage/runtime/compiled_templates/6a/6a6f101327b6562dac87535b77ee6df86b1fcf5127dbf96081dafc2bd3e04319.php(138): Twig\Template->display(Array, Array)
#22 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(407): __TwigTemplate_78b73f3c400b8cecce86003bbfe741acf24b622cf9ad120c1458b401cb251626->doDisplay(Array, Array)
#23 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#24 /Users/lexislav/Websites/koma-family.cz/storage/runtime/compiled_templates/e5/e5316a2fa0e2fb0c4bb255b6d2cc1c4dfda4e71921682f545a35f40232d9b45b.php(125): Twig\Template->display(Array, Array)
#25 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(407): __TwigTemplate_b1e9203863701efc8619b1e48c7cabdfe218c9d5a7a4f9e09937a0557e80411f->doDisplay(Array, Array)
#26 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#27 /Users/lexislav/Websites/koma-family.cz/storage/runtime/compiled_templates/11/112770e1ae10c01341efe56b562866b8579470fe002efa6a7af67a6cd2222ffd.php(46): Twig\Template->display(Array, Array)
#28 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(407): __TwigTemplate_8739459ef56725941c383f54d4413eb3560b86bcba36f77082192ae849cc1840->doDisplay(Array, Array)
#29 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#30 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Template.php(392): Twig\Template->display(Array)
#31 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#32 /Users/lexislav/Websites/koma-family.cz/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#33 /Users/lexislav/Websites/koma-family.cz/vendor/craftcms/cms/src/web/View.php(397): Twig\Environment->render('sprout-base/_se...', Array)
#34 /Users/lexislav/Websites/koma-family.cz/vendor/craftcms/cms/src/web/View.php(458): craft\web\View->renderTemplate('sprout-base/_se...', Array)
#35 /Users/lexislav/Websites/koma-family.cz/vendor/craftcms/cms/src/web/Controller.php(235): craft\web\View->renderPageTemplate('sprout-base/_se...', Array, 'cp')
#36 /Users/lexislav/Websites/koma-family.cz/vendor/barrelstrength/sprout-base/src/controllers/SettingsController.php(127): craft\web\Controller->renderTemplate('sprout-base/_se...', Array)
#37 [internal function]: barrelstrength\sproutbase\controllers\SettingsController->actionEditSettings(NULL)
#38 /Users/lexislav/Websites/koma-family.cz/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#39 /Users/lexislav/Websites/koma-family.cz/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#40 /Users/lexislav/Websites/koma-family.cz/vendor/craftcms/cms/src/web/Controller.php(178): yii\base\Controller->runAction('edit-settings', Array)
#41 /Users/lexislav/Websites/koma-family.cz/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('edit-settings', Array)
#42 /Users/lexislav/Websites/koma-family.cz/vendor/craftcms/cms/src/web/Application.php(291): yii\base\Module->runAction('sprout/settings...', Array)
#43 /Users/lexislav/Websites/koma-family.cz/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('sprout/settings...', Array)
#44 /Users/lexislav/Websites/koma-family.cz/vendor/craftcms/cms/src/web/Application.php(276): yii\web\Application->handleRequest(Object(craft\web\Request))
#45 /Users/lexislav/Websites/koma-family.cz/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#46 /Users/lexislav/Websites/koma-family.cz/web/index.php(21): yii\base\Application->run()
#47 {main}

Additional info

When update to Sprout Forms 3.9.0 we have some serious security issue, so this plugin was first step to try to reduce thousands of spam emails…

Pluginy

Moduly

For some issues, we may request that you send the following items to Support sprout@barrelstrengthdesign.com. If you feel your issue may fall in that category, feel free to send things over after you post this issue and reference the issue in your email.

brianjhanson commented 4 years ago

@lexislav just ran into this as well.

I dug around a bit and TL;DR you can patch it (although maybe not in the best way) by changing GoogleRecaptchaL#88 to:

$settings = parent::getSettings() ?? [];

More Details It looks like parent::getSettings() is returning null instead of an array. That codes hasn't changed in 2 years, so not sure why it has suddenly stopped working.

You can see that getSettings call comes from the parent Captcha class which is returning null when no captchaSettings[$this->getCaptchaId()] settings are set.

I'm guessing Sprout Forms is expecting you to have something like

'catpchaSettings' => [
  '{id}' => [
    'someSetting' => 'value',
    'anotherSetting' => 'value'
  ]
]

within your sprout-forms.php file. However, this proves a bit difficult on the first setup because you don't have a good way of knowing the ID of the captcha when you can't create it.

EDIT After a bit more digging, it looks like the ID is sproutformsgooglerecaptcha-googlerecaptcha (which doesn't seem quite right, I feel like it should be sproutforms-googlerecaptcha) BUT either way, you can also fix this by adding something like:

    'captchaSettings' => [
        'sproutformsgooglerecaptcha-googlerecaptcha' => [
            'enabled' => 1,
            // The siteKey from your reCAPTCHA settings: https://www.google.com/recaptcha/admin
            'siteKey' => getenv('GOOGLE_RECAPTCHA_SITE_KEY'),

            // The secretKey from your reCAPTCHA settings: https://www.google.com/recaptcha/admin
            'secretKey' => getenv('GOOGLE_RECAPTCHA_SECRET_KEY'),
        ]
    ]

to your sprout-forms.php file. I would favor this slightly at the moment because you don't have to alter the plugin code.

lexislav commented 4 years ago

@brianjhanson Thanks. It is definitely the step forward for me.

Your answer (the edited one) gets me running. The only issue now is the lack of docs for Sprout Forms I guess (and its config file sprout-forms.php.)

There was no such file on my setup. So I have created it in /config. The plugin has started working. So I have filled the keys but wasn't able to render the form on fronted (some settings in the file were missing). So I have deleted the file sprout-forms.php and it all works now. The settings once initiated fixed the issue.

However, more questions have popped up - is there a way to choose different captchas strategies for different forms on the same site? To use different languages on multisite? I guess the answers are in the sprout-forms.php so I will try to get more info on config options.

brianjhanson commented 4 years ago

@lexislav you can get a decent idea of what settings are provided by checkout out the Settings Model unfortunately, I'm afraid I don't have answers for you on those other questions. I haven't needed to dive that deep into the code yet 🙂

BenParizek commented 4 years ago

Hi Folks, the issue here is that we're currently, mistakenly assuming you have settings in the plugin's config file sprout-forms.php. Adding those settings to the config file helps solve this for now.

I'll have a release out shortly that addresses this, improves our documentation and examples around the plugin config (but doesn't require that you use it), and updates that Captcha key to reference the Captcha namespace instead of a odd, lower-cased representation of the Captcha name which is a legacy naming convention that we need to update from Craft 2 conventions.

I'll update this thread when we get that out.

BenParizek commented 4 years ago

This issue has been resolved in the latest release.

If you hacked in a quick fix and are not using config overrides on your project, updating to the latest should continue to work as you got things working in your hack. If you happen to fix this using config overrides in your project you can remove those now or see the upgrade notes on where to place these settings in the config/sprout-forms.php config:

https://sprout.barrelstrengthdesign.com/docs/forms/installing-and-updating-craft-3.html#upgrading-to-forms-v3-10-0