Problem/Motivation

When using gin_login, the captcha is not placed correctly on the password reset form (it is placed below the submit button).
Not sure if that's a problem with captcha or with gin_login.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

prudloff created an issue.

dkmishra’s picture

CAPTCHA is rendering correctly. The issue is form element ordering.

The CAPTCHA module inserts the CAPTCHA before the form actions. After that, `gin_login_form_alter()` changes the login form layout and sets the actions wrapper weight to `98`, which moves the submit button above the CAPTCHA.

In `gin_login.module`:

/**
   * Form_alter()
   */
  function gin_login_form_alter(&$form, $form_state, $form_id) {
    // User form (Login, Register or Forgot password)
    if (strpos($form_id, 'user_login') !== FALSE || strpos($form_id, 'user_register') !== FALSE || in_array($form_id, ['user_pass'])) {
      $form['actions']['submit']['#attributes']['class'][] = 'button--primary';

      // Move actions before new elements.
      $form['actions']['#weight'] = '98';
    }
  }

So this looks like a Gin Login/CAPTCHA integration ordering issue, not a CAPTCHA rendering issue.

A safe project-level fix is to add a small custom form alter hook and explicitly keep CAPTCHA before the submit button:

/**
   * Implements hook_form_FORM_ID_alter() for user_login_form.
   */
  function MYMODULE_form_user_login_form_alter(array &$form, \Drupal\Core\Form\FormStateInterface $form_state): void {
    if (isset($form['captcha'])) {
      $form['captcha']['#weight'] = 97;
    }

    if (isset($form['actions'])) {
      $form['actions']['#weight'] = 98;
    }

    if (isset($form['more-links'])) {
      $form['more-links']['#weight'] = 99;
    }
  }

  /**
   * Implements hook_form_FORM_ID_alter() for user_pass.
   */
  function MYMODULE_form_user_pass_alter(array &$form, \Drupal\Core\Form\FormStateInterface $form_state): void {
    if (isset($form['captcha'])) {
      $form['captcha']['#weight'] = 97;
    }

    if (isset($form['actions'])) {
      $form['actions']['#weight'] = 98;
    }

    if (isset($form['more-links'])) {
      $form['more-links']['#weight'] = 99;
    }
  }

After adding this, clear Drupal cache.