Skip to content

Commit

Permalink
Fix issue if MBK forms is not setup correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangittings authored May 10, 2022
1 parent aa2fdb5 commit 8da6e5f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mbk_forms/runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ function mbk_forms_form_handler($form) {
$Settings = $API->get('Settings');
$data = $form->data;
$responseKey = null;
$secretKey = $Settings->get('mbk_forms_recaptcha_secret_key')->val();

// This is what the widget returns when submitting the form
if(isset($data['g-recaptcha-response'])) {
$responseKey = $data['g-recaptcha-response'];
}

$recaptcha = new \ReCaptcha\ReCaptcha($Settings->get('mbk_forms_recaptcha_secret_key')->val());
$recaptcha = new \ReCaptcha\ReCaptcha($secretKey);
$response = $recaptcha->verify($responseKey, $_SERVER['REMOTE_ADDR']);

if (!$response->isSuccess()) {
if ($responseKey && $secretKey && !$response->isSuccess()) {
$form->data[$Settings->get('mbk_forms_honeypot_name')->val()] = 'Failed captcha';
}

Expand Down Expand Up @@ -47,4 +48,4 @@ function mbk_forms_form_handler($form) {
$form->redispatch($app);
}
}
}
}

0 comments on commit 8da6e5f

Please sign in to comment.