Hi

Please, where the HTML is located?

<div class="form-item form-type-password form-item-pass">
  <label class="element-invisible" for="edit-pass--3">Password <span class="form-required" title="This field is required.">*</span></label>
 <input placeholder="Password" id="edit-pass--3" name="pass" size="15" maxlength="128" class="form-text required" type="password">
</div>

I need to insert a link a href after the password field:

<input placeholder="Password" id="edit-pass--3" name="pass" size="15" maxlength="128" class="form-text required" type="password"><a href="password-reset">Password reset</a>

and I do not understand where it is located.
I look at user.module file but can not see it there.

Thank you

Comments

VM’s picture

may aid to understand what you are trying to do as hacking user.module may not be the way you want to interact.

trk_’s picture

I would like to insert a link. Nothing more.

I think this is possible to hard code in?
But I can not find the place (file) where it should be done.

Thank you :)

VM’s picture

hacking core/contrib files is always possible. the question should be is it warranted. In your situation (most situations) hacking core/contrib files isn't warranted as one can utilize hooks and preprocessing function interact with core. Hacking core files creates a tedious update/upgrade process for no reason.

trk_’s picture

Sure, I know this situation.
But I work this way many years.

Jaypan’s picture

You need to implement hook_form_alter() and add your link as a #markup element to that.

I know the above does not make sense to you, so you'll need to spend some time learning how Drupal hooks work and module development works: https://www.drupal.org/documentation/develop

trk_’s picture

Jaypan, thank you but it is not what I need.

trk_’s picture

I have this code:

function bartik_form_alter( &$form, &$form_state, $form_id )
{
        if($form_id == 'user_login_block')
    {
        $form['links']['#markup'] = '';
    }
    if (in_array( $form_id, array( 'user_login', 'user_login_block', 'user_register_form')))
    {
        $form['name']['#attributes']['placeholder'] = t( 'Username' );
        $form['pass']['#attributes']['placeholder'] = t( 'Password' );
		$form['account']['name']['#attributes']['placeholder'] = t( 'Pick a username' );
		$form['account']['pass']['#attributes']['placeholder'] = t( 'Create a password' );
		$form['name']['#title_display'] = 'invisible';
		$form['pass']['#title_display'] = 'invisible';
		$form['account']['name']['#title_display'] = 'invisible';
		$form['account']['pass']['#title_display'] = 'invisible';
		$form['account']['pass']['#description'] = '';
		$form['account']['name']['#description'] = '';
    }
}
trk_’s picture

If I place a link in

    {
        $form['links']['#markup'] = '<a href="reset-password">Reset password</a>';
    }

then it is placed in wrong place, out off the div

<div class="form-item form-type-password form-item-pass">
  <label class="element-invisible" for="edit-pass--3">Password <span class="form-required" title="This field is required.">*</span></label>
 <input placeholder="Password" id="edit-pass--3" name="pass" size="15" maxlength="128" class="form-text required" type="password">
</div>

<a href="reset-password">Reset password</a>

It should be inside the div:

<div class="form-item form-type-password form-item-pass">
  <label class="element-invisible" for="edit-pass--3">Password <span class="form-required" title="This field is required.">*</span></label>
 <input placeholder="Password" id="edit-pass--3" name="pass" size="15" maxlength="128" class="form-text required" type="password">

<a href="reset-password">Reset password</a>
</div>


nitin.k’s picture

You need to use hook_form_BASE_FORM_ID_alter() function. Put the below function in template.php


/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function themename_form_user_login_alter(&$form, &$form_state, $form_id) {

  // Method - 1

  $form['pass']['#prefix'] = '<div class="pass_wrapper">';
  $form['pass']['#suffix'] = '</div><a href="#">Click the link ..</a><h1>';

// Method - 2
  $markup = l(t('Link'), '#', array('attributes' => array('title' => t('Link'))));
  $markup = '<div class="clearfix">' . $markup . '</div>';
  $form['links']['#markup'] = $markup;
}


trk_’s picture

Thank you but your code does not work the way I need.

I need to add a link after the password input (inside div wrapper) and your code adds a link outside of it:

<input></div><a>link</a>

Should be:

<input><a>link</a></div>

trk_’s picture

This does not work

function bartik_form_user_login_alter(&$form, &$form_state, $form_id) {

  $form['pass']['#prefix'] = '<div class="pass_wrapper">';
  $form['pass']['#suffix'] = '<a href="#">link</a></div>';

}

This adds a link outside of the password input div wrapper.
Should be inside.

This code does not change my login box it should be.
It changes only admins login at user/login - I do not need it.

Thank you for help

Jaypan’s picture

If you need it to be inside, you'll need to instead override theme_password() in your theme.

trk_’s picture

Too difficult to understand for me.

Very simple question - where is the place I could directly put my link in. (without any hook codings - I do not need this additional problem)

Thank you

trk_’s picture

Thank you very much

I do understand now - it is form.inc file.
This is exactly what I need

Jaypan’s picture

If that worked for you, that's great.

For anyone else who may stumble across this thread however, this is one of the biggest no-no's in Drupal - shouldn't hack core files. Your changes will be overwritten on the next core update, or you'll have to remember to go in and make the change again.

trk_’s picture

What alternative?

If the hook https://www.drupal.org/node/2799623#comment-11621425 can not place the link exactly in the neccessary place.

Or there is another hook to achieve the task?

trk_’s picture

Jaypen, this is not appropriate solution to add a link in function theme_password($variables)

If I do this then my link is added to all password fields.
But I need it only for the password field located in the login block.

May be there is another place in the core where the block password input exist?

Thank you