Dear all,
my website (www.familleloup.com) integrates Simplenews and Captche module.
The newsletter subscription form does not show the captcha, whereas it does work on contact form.
Using the "add Captcha tool", I am led to a page where both system name and form ID are filled.
because form ID is very long (67 characters), and system name deviated from form ID,, I have to modify system name.
The captcha pont is visible on the list, but browsing to the newsletter subscription does not show the captcha.
thanks for any comment. Cheers

Comments

fred@familleloup.com created an issue. See original summary.

sumithb’s picture

Same issue

saurabh.dhariwal’s picture

@fred@familleloup.com @sumithb, You just have to follow the code that I added blow, That works for me.

>> Get the subscription form_id & on form alter add the mentioned code, to get the captcha on a Subscription form

/*

* Implements hook_form_alter()

*/

function mymodule-name_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {

  if($form_id == 'form_id') {

     $form['captcha'] = array (

    '#type' => 'captcha',

    '#captcha_type' => 'recaptcha/reCAPTCHA'

    );

  }

}

Hope this helps you. Thanks!.

couturier’s picture

Status: Active » Postponed (maintainer needs more info)

Any update on whether this solved the issue?

labiloute@neuf.fr’s picture

Up !
I encounter the same bug but I am unable to understand the workaround provided by @saurabh.dhariwal ...
Cheers

labiloute@neuf.fr’s picture

Ok !
I finaly got it :

Open "modules/contrib/simplenews/simplenews.module" file from your Drupal 8 installation path (with module simplenews installed)

Add the following code at line :

// HACK

 if($form_id == 'form_id') {
     $form['captcha'] = array (
    '#type' => 'captcha',
    '#captcha_type' => 'recaptcha/reCAPTCHA'
    );
}

// \ HACK

Just after :

function simplenews_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
  $options = $default_value = $hidden = array();

Hope this helps.
Cheers :)

igormagic’s picture

Category: Support request » Bug report
Anybody’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)