Skip to content

Commit

Permalink
Added the option to disable automatic contact form validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-west committed Oct 8, 2018
1 parent cd7a4a7 commit eb097da
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .craftplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"pluginName": "Craft reCAPTCHA",
"pluginDescription": "Integrate Google’s reCAPTCHA into your forms.",
"pluginVersion": "1.1.0",
"pluginVersion": "1.2.0",
"pluginAuthorName": "Matt West",
"pluginVendorName": "mattwest",
"pluginAuthorUrl": "https://mattwest.io",
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "matt-west/craft-recaptcha",
"description": "Integrate Google’s reCAPTCHA into your forms.",
"type": "craft-plugin",
"version": "1.1.0",
"version": "1.2.0",
"keywords": [
"craft",
"cms",
Expand Down
4 changes: 3 additions & 1 deletion src/CraftRecaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ function (PluginEvent $event) {
);

// Set up contact form hook.
if (class_exists(Submission::class)) {
$settings = CraftRecaptcha::$plugin->getSettings();

if (class_exists(Submission::class) && $settings->validateContactForm) {
Event::on(Submission::class, Submission::EVENT_BEFORE_VALIDATE, function(ModelEvent $e) {
/** @var Submission $submission */
$submission = $e->sender;
Expand Down
3 changes: 2 additions & 1 deletion src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@

"siteKey" => "",
"secretKey" => "",

"validateContactForm" => true,

];
7 changes: 7 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class Settings extends Model
*/
public $secretKey = '';

/**
* Validate ContactForm submissions
*
* @var bool
*/
public $validateContactForm = true;

// Public Methods
// =========================================================================

Expand Down
11 changes: 11 additions & 0 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@
value: settings['secretKey'],
required: true})
}}


<hr>

{{ forms.lightswitchField({
label: 'Validate contact forms?',
instructions: 'Enable to automatically validate reCAPTCHAs when using the official [Craft CMS contact form plugin](https://github.com/craftcms/contact-form).',
id: 'validateContactForm',
name: 'validateContactForm',
on: settings['validateContactForm']})
}}
1 change: 1 addition & 0 deletions src/translations/en/recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
'Secret Key' => 'Secret Key',
'Enter your reCAPTCHA site key.' => 'Enter your reCAPTCHA site key.',
'Enter your reCAPTCHA secret key.' => 'Enter your reCAPTCHA secret key.',
'Validate contact forms?' => 'Validate contact forms?',
];

0 comments on commit eb097da

Please sign in to comment.