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

Google reCaptcha v3 integration #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[general]
page=home
[email protected]
language=en_US
language=en_US
reCaptchaSiteKey=0
31 changes: 27 additions & 4 deletions contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* It allows to add and manage additional contents on a page.
*
* @author Thijs Ferket www.ferket.net
* @forked and adapted by Herman Adema
* @forked and adapted by Herman Adema
* @forked by Jeremy Czajkowski
* @forked by Robert Isoski @robiso
* @version 3.0.0
Expand All @@ -23,9 +23,14 @@
define('CONTACT_FORM_PAGE', $configuration ['page']);
define('CONTACT_FORM_EMAIL', $configuration ['emailAddress']);
define('CONTACT_FORM_LANG', $configuration ['language']);
define('CONTACT_FORM_RECAPTCHA_SITE_KEY', $configuration ['reCaptchaSiteKey']);

$Wcms->addListener('css', 'contactfCSS');

if (CONTACT_FORM_RECAPTCHA_SITE_KEY) {
$Wcms->addListener('js', 'recaptchaJS');
}

function contactfCSS($args) {
global $Wcms;

Expand All @@ -34,6 +39,19 @@ function contactfCSS($args) {
return $args;
}

function recaptchaJS($args) {
global $Wcms;

$script = '<script src="https://www.google.com/recaptcha/api.js?render='.CONTACT_FORM_RECAPTCHA_SITE_KEY.'"></script>';
$script .= '<script>
function onSubmit(token) {
document.getElementById("wonder-cms-form").submit();
}
</script>';
$args[0].=$script;
return $args;
}

function contactfCONTENT() {
global $Wcms;

Expand Down Expand Up @@ -164,7 +182,7 @@ function checkmail($email) {
}
else {
$sent = false;
}
}
// header ('Location: ' . $_SERVER['REQUEST_URI']);
if ($sent) {
echo "<h4 class='text-center'<br /><br />" . $i18n['result_sent'] . "</h4>";
Expand All @@ -184,7 +202,7 @@ function checkmail($email) {
}
$final_content .= "<div id='containerform'>";

$final_content .= "<form method='post' action=''>";
$final_content .= "<form id='wonder-cms-form' method='post' action=''>";
$final_content .= "<p>";
$final_content .= "<div class='form-group'><input type='text' placeholder='$i18n[name]' id='name' name='name' maxlength='30'";
if(isset($fout['input']['name'])) { $final_content .= "class='fout'"; } $final_content .= "value='";
Expand All @@ -201,8 +219,13 @@ function checkmail($email) {
$final_content .= "<div class='form-group'><textarea placeholder='$i18n[message]' id='message' name='message'";
if(isset($fout['input']['message'])) { $final_content .= "class='fout'"; } $final_content .= " cols='31' rows='10'>";
if (!empty($message)) { $final_content .= stripslashes($message); } $final_content .= "</textarea></div>";

$recaptcha_btn_attr = ' ';
if (CONTACT_FORM_RECAPTCHA_SITE_KEY) {
$recaptcha_btn_attr = "data-sitekey='".CONTACT_FORM_RECAPTCHA_SITE_KEY."' data-callback='onSubmit' data-action='submit'";
}

$final_content .= "<input type='submit' id='submitForm' class='btn btn-primary btn-block' name='submitForm' value='$i18n[submit]' />";
$final_content .= "<input type='submit' id='submitForm' class='btn btn-primary btn-block' name='submitForm' value='$i18n[submit]' ".$recaptcha_btn_attr." />";
$final_content .= "</p>";
$final_content .= "</form>";
$final_content .= "</div>";
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1
3.0.2