I want to remove the descriptions on login page. I tried removing it from user.module, but still it showed up. I am using Form placeholder module and Betterlogin module to enhance the login page. Please suggest.

Comments

VM’s picture

per: https://www.drupal.org/node/644164 please edit the opening post and move it to the 'post installation' forum. Thank you.

silypointer’s picture

Please do as VM said.

Please have a look at the code snipped and try to reproduce such thing in your custom module.

function hook_form_alter(&$form, &$form_state,$form_id) {
	if($form['#form_id'] == 'user_login') {
		unset($form['name']['#description']);	
		unset($form['pass']['#description']);	
	}
}

This will remove the description below the Login Form fields.

AshwinB’s picture

I don't have any custom developed modules. 'Betterlogin' and 'Form Placeholder' modules are already available. I already tried inserting the code you suggested in betterlogin.module and form_placeholder.module. But this resulted in a fatal error. Am I missing anything?

VM’s picture

you do not hack core or other modules and add code. You put code in your own custom.module. see: http://websmiths.co/blog/very-introduction-drupals-hookformalter for a better understanding. Also of note you will need to modify the snippet provided. You can't just add it.

Else use CSS to hide the element.

silypointer’s picture

Amaster123,

You cannot just add the provided code in betterlogin.module please check https://www.drupal.org/best-practices/do-not-hack-core

You need to create a custom module for that, Link shared by VM is very useful, please refer it.

Thanks!

AshwinB’s picture

Ok. Thanks for this important know-how.!

AshwinB’s picture

I did exactly as told in https://www.drupal.org/node/754542#comment-2775706 But this also didn't worked. Are there any modifications to make? (as I am a beginner in this field, still learning).

AshwinB’s picture

As mentioned in https://www.drupal.org/node/2351093#comment-9221203 by VM, what modifications do I need to make in

function hook_form_alter(&$form, &$form_state,$form_id) {
	if($form['#form_id'] == 'user_login') {
		unset($form['name']['#description']);
		unset($form['pass']['#description']);
	}
}
VM’s picture

what is the name of your module? did you include it in the function name? show us the code you yourself wrote.

AshwinB’s picture

I made two files.
1. alterlogin.info
2. alterlogin.module

alterlogin.info

name = alterlogin
description = Alter the user login form
core = 7.x
files[] = alterlogin.module

alterlogin.module

<?php

/**
 * Implements hook_form_alter().
 */
function hook_form_alter(&$form, &$form_state, $form_id) {
 
  if ($form_id == 'user_login') {
 
    $form['name']['#description'] = '';
    $form['pass']['#description'] = '';
 
  }
 
}
?>

I placed these two files in a folder named 'alterlogin' and placed the folder in sites/all/modules directory; enabled the module; cleared the cache; and nothing seems to work.

As a note:- when I was reading betterlogin.module, I found

unset($form['name']['#description']);
    unset($form['pass']['#description']);

Is this anything that matters?

VM’s picture

function hook_form_alter

note the function name in your snippet above. Then refer back to the this thread where you are pulling the alterlogin.module snippet. See the differences in the function name?

also of note you switched the code you were provided

unset($form['name']['#description']);
unset($form['pass']['#description']);

with:

$form['name']['#description'] = '';
$form['pass']['#description'] = '';

why?

have you tried something like the following?:

// remove description from user login form text fields
function alterlogin_form_user_login_alter(&$form, &$form_state) {
unset($form['name']['#description']);
unset($form['pass']['#description']);
}

If it still doesn't work, I'd disable and uninstall the better login module and test.

AshwinB’s picture

Thanks...VM...All my mistake. Actually the function alterlogin_form_user_login_alter(&$form, &$form_state) didn't worked. But what I did, was, I added

div.description {
display:none;
}

In the css of betterlogin module.

VM’s picture

you shouldn't be hacking files. CUSTOM CSS should go into your own custom.css file within your subtheme.

When you update core or a module changes will be overwritten when you hack files.

Red Sky Tom’s picture

The hook that VM gave you should have worked. Keep in mind that from my understanding modules are loaded alphabetically (or weight if assigned) so that what you wrote in the Afterlogin module might have gotten overridden by a module that came after it.

Cheers,

Drupal Development and Consulting.

cliffb’s picture

I realise this is an old thread but the problem is you were targeting the wrong element. It should have been:

unset($form['account']['name']['description']);