Skip to content

Commit

Permalink
Better invisible reCaptcha implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-vince committed Apr 20, 2023
1 parent 2404cfe commit 268b091
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
4 changes: 3 additions & 1 deletion components/SmallContactForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,9 @@ public function getFormAttributes(){
$attributes['files'] = true;

// Disabled hard coded hash URL in 1.41.0 as dynamic redirect is now available
// $attributes['url'] = '#scf-' . $this->alias;
if ( empty(Settings::getTranslated('allow_redirect', null) ) ) {
$attributes['url'] = '#scf-' . $this->alias;
}

$attributes['method'] = 'POST';
$attributes['class'] = null;
Expand Down
42 changes: 22 additions & 20 deletions components/smallcontactform/scf-form.htm
Original file line number Diff line number Diff line change
Expand Up @@ -66,39 +66,41 @@

{% if settingsGet('google_recaptcha_version') == 'v2invisible' %}
,
'size' : "invisible"
{% endif %}

{% if settingsGet('google_recaptcha_version') == 'v2invisible' %}
,
'size' : "invisible",
'callback' : onSubmit_{{__SELF__.alias}}

{% endif %}

}
);
};

{% if settingsGet('google_recaptcha_version') == 'v2invisible' %}
{% if settingsGet('google_recaptcha_version') == 'v2invisible' %}

$('#scf-form-id-{{ __SELF__.alias }} button[type=submit]').click(function (event) {
$('#scf-form-id-{{ __SELF__.alias }} button[type=submit]').click(function (event) {

event.preventDefault();
event.preventDefault();

var formRecaptchaObject = document.getElementById('g-recaptcha-{{ __SELF__.alias }}');
var formRecaptchaObject = document.getElementById('g-recaptcha-{{ __SELF__.alias }}');

grecaptcha.execute();

});
grecaptcha.execute();
});

function onSubmit_{{ __SELF__.alias }}(token) {
function onSubmit_{{ __SELF__.alias }}(token) {

$('form[id^="scf-form-id"]').each(function(){
$(this).submit();
});
$('form[id^="scf-form-id"]').each(function(){

}
{% if settingsGet('form_allow_ajax', null) %}
$(this).request();
{% else %}
$(this).submit();
{% endif %}
});

{% endif %}
}

{% endif %}

};


</script>
Expand Down
4 changes: 3 additions & 1 deletion updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,6 @@
1.63.0:
- Added option to disable PLAIN post when AJAX is enabled (thanks @TimFoerster)
1.63.1:
- Fixed reCaptcha script
- Fixed reCaptcha script
1.63.2:
- Better invisible reCaptcha implementation

0 comments on commit 268b091

Please sign in to comment.