This module has all the code needed to add a captcha to a webform, but we have a slightly different use case. We don't want captchas added to every webform. We want users to have the option of adding it... or possibly adding at as the default, but give uses the option of disabling it. Adding this option to the webform's form settings is a very simple form alter, but requires adding logic to the _captcha_webform__set_webform_captcha function.

I understand this module is super simple and this change adds complexity, but since I have to do this I thought I'd ask. If your not interested in adding this, I will create a fork.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kreynen’s picture

Issue summary: View changes
FileSize
4.05 KB

I tried to keep this as small as possible. This patch adds an admin form in the Captcha configuration w/ 2 options specific to Webforms...

1) Enable the default Captcha for all new Webforms when they are created
2) Display option to enable or disable captcha in Webform settings

This allows anyone with access to a Webform's form settings to control if the default captcha is displayed or not. Still needs an update hook to set the variables to avoid causing problems for existing installs, but I thought I'd like to know if you are even interested in adding this functionality.

tregismoreira’s picture

Hey @kreynen. Thanks for your contribution!

I think it's a good feature. I will test the patch and give you a feedback asap.

kreynen’s picture

FileSize
4.64 KB

I've cleaned the patch up and added the update hook to the .install. We deployed this as part of an update to our standard distribution used by hundreds of CU Boulder sites. So far, no issues. By using the captcha settings to store the on/off state for each webform, changes can be made through either the webform's form settings or the normal captcha UI.

tregismoreira’s picture

Hey @kreynen. Thanks again!

I tested your patch and it's works like a charm. Congrats.

I've some suggestions:

1. Your patch is not in accordance with standard naming convention;

2. As your captcha_webform_update_7101 set captcha_webform_enabled_by_default to TRUE, maybe this variable must be TRUE at all. So on field captcha_webform_enabled_by_default you could change default_value to variable_get('captcha_webform_enabled_by_default', 1).

3. In captcha_webform_form_alter isn't better to write like this?

    $form['webform-captcha'] = array(
      '#type' => 'fieldset',
      '#title' => t('SPAM Prevention'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );

    $form['webform-captcha']['user-config'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable Captcha')
      '#default_value' => $webform_captcha_state
    );

Again, congrats and thanks ;)

kreynen’s picture

Status: Active » Needs review

Sorry I missed your response. Regarding patch file naming, that really isn't a standard as much as a legacy drupalism the many developers are working to get away by contribution to efforts like #2488266: [META] Improve Git workflow on Drupal.org by implementing issue workspaces. If I could use a PR, I would.

The goal of captcha_webform_update_7101 was to keep everything working the same way it was before the change for the > 800 reported installs, but require a decision about the configuration on new installs.

As far as #3, that's just a style preference. While $form['webform-captcha'] = array( looks cleaner for simple form, it looks worse for more complicated forms where there are nested arrays.

kreynen’s picture

ping... we are pushing an update to our distribution after the 4th and I'd like to replace the patch version of this with at least of dev snapshot if possible.

lias’s picture

Bumping for attention

kreynen’s picture

Status: Needs review » Closed (won't fix)

Gave up on getting @tregismoreira to respond. We don't like running patched projects maintained by unresponsive maintainers very long. To resolve this for the University of Colorado, I created https://www.drupal.org/project/webform_captcha and merged the original functionality with this patch.

tregismoreira’s picture

Status: Closed (won't fix) » Closed (fixed)

Commited and released in 7.x-1.2.

Thanks, @kreynen.