Hi guys,
Here is how to add "Forgot your password?" link just before the "Log in" button:
- find this line inside the drop_down_login.module:
Line 105:

   if ($form_id == 'user_login') {

- insert this line right after it:

  $form['link'] = array('#markup' => l(t('Forgot your password?'),'user/password'));

I also needed this added to drop_down_login\theme\drop_down_login.css to have some space between added link and "Log in" button (not only on the Drop Down Login form, but all user-login forms, e.g. user/login):

[id^="user-login"] .btn {
    margin-top: 10px;
}

Thank you,
Gennady

Comments

gennadiy’s picture

Issue summary: View changes
gennadiy’s picture

Issue summary: View changes
nashkrammer’s picture

Hi @gennadly,

Thanks for your inputs. I'll add the 'forgot password' link as you suggested. I am also working on a settings page for the same.

Thank You
-Avinash

dgregory’s picture

I think that a register link would be a great feature on the drop down login as well.

sdsheridan’s picture

I'd do this slightly differently, as follows:

  1. Pass a parameter in the call to drupal_get_form, as follows:
            $rendered_user_login_form = drupal_get_form('user_login', 'drop_down_login');
    

    The parameter will get passed along to all alter functions in $form_state['build_info']['args'] (which is an array) as an array element.

  2. Change the hook from hook_form_alter to hook_form_FORM_ID_alter, so that your function is only called for the user_login form, and not all forms. That way too, you don't have to test the $form_id in the "if" statement.
    /**
     * Implements hook_form_FORM_ID_alter().
     */
    function drop_down_login_form_user_login_alter(&$form, &$form_state, $form_id) {
    

    Don't forget to clear caches if you're doing this real-time, so the hook information gets regenerated. Otherwise, you won't see the alterations to the form.

  3. In that surrounding "if" statement in drop_down_login_form_user_login_alter, instead of checking the $form_id, test for the parameter passed, so you're only modifying the form you're generating for your dropdown, and not every user_login form everywhere:
    function drop_down_login_form_user_login_alter(&$form, &$form_state, $form_id) {
      if (in_array('drop_down_login', $form_state['build_info']['args'])) {
    

    This will eliminate side-effects from your module colliding with how other modules may be modifying the regular user-login form, block, and page.

  4. Include the links for password reset and registration as follows in the hook_form_user_login_alter function. The code below wraps both links inside their own divs, and then inside an overall div to facilitate theming and placement (via the #weight attribute in the outer div).
        $form['drop_down_login_reset_register'] = array(
          '#prefix' => '<div class="drop_down_login_reset_register_links">',
          '#suffix' => '</div>',
          '#weight' => 100,
        );
        $form['drop_down_login_reset_register']['reset_password'] = array(
          '#markup' => l(t('Forgot your password?'),'user/password'),
          '#prefix' => '<div class="drop_down_login_reset_password">',
          '#suffix' => '</div>',
        );
        if ( in_array(variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL), array(USER_REGISTER_VISITORS, USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL,)) ) {
          $form['drop_down_login_reset_register']['register'] = array(
            '#markup' => l(t('Register for an account...'), 'user/register'),
          '#prefix' => '<div class="drop_down_login_register">',
          '#suffix' => '</div>',
          );
        }
        // Validate handler for login form.
        $form['#validate'][] = 'drop_down_login_validate_login';
        // Submit handler for login form.
        $form['#submit'][] = 'drop_down_login_submit_login';
    

    Notice too I changed the double-quotes around #validate and #submit to single quotes to avoid invoking PHP's string replacement feature, which is clearly not needed here, and thus improves performance a bit.

  5. Doing it this way, there was no need for any CSS changes (because things are wrapped in divs).

I think these changes make the module a bit better performance-wise, and fully featured, with no side-effects on other modules.

Shawn

sdsheridan’s picture

Oh, and while we're at it, we could add a slight enhancement to the .js to place focus in the login name when the box drops down, as follows:

/**
 * @file
 * Javascript and jQuery functions which are useful for the drop_down_login module.
 */

(function($, Drupal) {
  // Drupal.behaviors.
  Drupal.behaviors.drop_down_login = {
    attach:function(context, settings) {
      // Drop down login animation.
      $('#drop-down-login-wrapper',context).addClass('enable-dd');
      $('#drop-down-login-wrapper .login',context).click(function() {
        $(this).toggleClass('open').siblings('.dropdown').slideToggle("slow");
        if ( $(this).hasClass('open') ) {
          $(this).siblings('.dropdown').find('#edit-name').focus();
        }
        return false;
      });
    }
  };
}(jQuery, Drupal));

Shawn

sandeep.kumbhatil’s picture

Assigned: Unassigned » sandeep.kumbhatil
Status: Active » Needs review

Added the link for Forgot password and Signup, Also added a setting form to enable / disable the same. Added feature to enable my account and extra links under drop down.

nashkrammer’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Needs review » Fixed

Hi,

This issue is fixed in the dev version. Initial as Sandeep added a configuration for the forgot passord link in the block, later the block is replaced with the one that is used by the core i.e "user_login_block" instead of "user_login". This allows to render "create new account" and "request new password" links by default.

sandeep.kumbhatil’s picture

Status: Fixed » Closed (fixed)