Add links to login block

  • 10 January 2013
  • mohit.aghera

In one of my requirement I had two registration for two users. User had two roles. We have to build seperate form for two user registration.

I created two profiles using profile2 module and using profile2reg path module i got the seperate distrinct registration url for both the roles.

By registrating from the specific url user will automatically get the respective role.

Now to give the seperate registration link for user we have to alter registration form using hook_form_alter() function.

Here is the code snippet how to achieve it.

In any case if we want to add some more links to user registration then we can add it using hook_form_alter() function.

 * Implementation of hook_form_alter().
 * The purpose of this function is to add link for the registration of "Company" and "Employee" accounts.
 * We are unsetting the default user/register link and adding two more links for the registration purpose.
 * @param array $form
 * @param array $form_state
function modulealter_form_user_login_block_alter(&$form, &$form_state){
$item = array();
if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
$items[] = l(t('Create Employee account'), 'employee/register', array('attributes' => array('title' => t('Create a new employee account.'))));
$items[] = l(t('Create Company account'), 'company/register', array('attributes' => array('title' => t('Create a new company account.'))));
$items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('If you forgot your password, click to request a new password via e-mail.'))));
$form['links']['#markup'] = theme('item_list', array('items' => $items));


abualk's picture

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck!

Brucewayne's picture

To get distinct registration url for different roles is a difficult task. I was wondering how to add links to login block. You spared me a lot of time. Thanks for sharing this valuable info. Keep sharing theses sort of informative data.

windows 7 technical support

Add new comment