Skip to content

Commit b3717b0

Browse files
authored
Merge pull request #5 from AlexStack/dev
Add theme-dark and no-api-js
2 parents 8fb3583 + 6c64802 commit b3717b0

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ GoogleRecaptcha::show($SiteKey, 'Form_ContactForm_Message', 'no_debug', 'mt-4 mb
5959
- '\$SiteKey': The Google Recaptcha Site Key of your website. You can directly put site key here or a variable or from database.
6060
- 'Form_ContactForm_Message': Form_Field_ID, via html code. eg. ... `<input type="text" id="Form_ContactForm_Message" />` ... Your Google Recaptcha will display after this form field.
6161
- 'no_debug': Change to debug and not tick the I'm not a robot checkbox will continue submit the form, then you will see the failed message.
62-
- 'mt-4 mb-1': Extra css class name for the Google Recaptcha area.
62+
- 'mt-4 mb-1': Extra css class name for the Google Recaptcha area. For recaptcha v2: Add theme-dark if you want the dark theme instead of the light. Add no-api-js if you already import the recaptcha/api.js.
6363
- 'Please tick the reCAPTCHA checkbox first': Frontend alert message if the end user does not tick the checkbox. **Tips:** You can change this value to "v3", it will automatically switch to use Google Recaptcha v3
6464
- Default value of the parameters of the show() method
6565

src/AlexStack/GoogleRecaptchaToAnyForm/GoogleRecaptcha.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,20 @@ public static function show($site_key, $after_field_id = 'Form_ContactForm_Comme
100100
return Self::showInvisible($site_key, $after_field_id, $debug, $extra_class);
101101
}
102102

103+
$api_js_str = "<script src='https://www.google.com/recaptcha/api.js'></script>";
104+
if ( strpos($extra_class, 'no-api-js') !== false ){
105+
$api_js_str = "";
106+
}
107+
$data_theme = 'light';
108+
if ( strpos($extra_class, 'theme-dark') !== false ){
109+
$data_theme = "dark";
110+
}
111+
103112
$debug_alert = ($debug == 'no_debug') ? 'false' : 'true';
104113
$str = <<<EOF
105114
<!-- Start of the Google Recaptcha v2 code -->
106115
107-
<script src='https://www.google.com/recaptcha/api.js'></script>
116+
$api_js_str
108117
<script>
109118
110119
// Display google recaptcha
@@ -123,7 +132,7 @@ function alexFindClosestNode(el, selector) {
123132
124133
var alexEL = document.getElementById('$after_field_id');
125134
if ( alexEL ) {
126-
alexEL.parentNode.insertAdjacentHTML('afterend', '<div class="g-recaptcha $extra_class" data-sitekey="$site_key"></div>');
135+
alexEL.parentNode.insertAdjacentHTML('afterend', '<div class="g-recaptcha $extra_class" data-sitekey="$site_key" data-theme="$data_theme"></div>');
127136
128137
// Validate google recaptcha before submit the form
129138
alexFindClosestNode(alexEL,'form').addEventListener('submit',function(e){

0 commit comments

Comments
 (0)