Alter The User Login Form Into Multi Steps I want to alter my default user login form into multi step. therefore I have wrote a code which I'm pasting below. but this code is not working, whenever I click on "Next" button it will return on the first step. please help me to get rid out of this problem.
Here is my code:

function signin_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'user_login' || $form_id == 'user_login_block') {
    unset($form['name']);
    unset($form['pass']);
    unset($form['actions']);
    $form['mail'] = [
      '#title'       =&gt; t('Email'),
      '#description' =&gt; t('Enter your Email'),
      '#type'        =&gt; 'textfield',
      '#required'    =&gt; 'true',
      '#maxlength'   =&gt; 40,
    ];
    $form['next'] = [
      '#name'   =&gt; 'next',
      '#value'  =&gt; t('Next'),
      '#type'   =&gt; 'submit',
      '#submit' =&gt; ['signin_step1_form_submit'],
    ];
    $form['#validate'] = ['signin_step1_form_validate'];
  }
}

function signin_step1_form_validate($form, &amp;$form_state) {
  $mail = $form_state['values']['mail'];
  if (empty(user_load_by_mail($mail))) {
    drupal_set_message(t('The entered email is not associated with any account.'));
  }
}

function signin_step1_form_submit($form, $form_state) {
  $form_state['stored_values']['mail'] = $form_state['values']['mail'];
  return signin_step2_form($form, $form_state);
}

function signin_step2_form($form, &amp;$form_state) {
  $form['pass'] = [
    '#title'       =&gt; t('Password'),
    '#description' =&gt; t('Enter the password'),
    '#type'        =&gt; 'password',
    #required' =&gt; 'true',
  ];
  $form['signin'] = [
    '#name'   =&gt; 'signin',
    '#value'  =&gt; t('SignIn'),
    '#type'   =&gt; 'submit',
    '#submit' =&gt; ['signin_step2_form_submit'],
  ];
  $form['#validate'] = ['signin_step2_form_validate'];
}

function signin_step2_form_validate($form, &amp;$form_state) {
  $mail = $form_state['stored_values']['mail'];
  $user_obj = user_load_by_mail($mail);
  $name = $user_obj-&gt;name;
  $pass = $form_state['values']['pass'];
  if (!user_authenticate($name, $pass)) {
    drupal_set_message('error', t('The Password you entered is incorrect'));
  }
}

function signin_step2_form_submit($form, &amp;$form_state) {
  $mail = $form_state['stored_values']['mail'];
  $user_obj = user_load_by_mail($mail);
  $form_state['uid'] = $user_obj-&gt;uid;
  user_login_submit($form, $form_state);
}
Finally I got it to worked. here is my code, I'm pasting this here to saves someone time.

function signin_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'user_login' || $form_id == 'user_login_block') {
    unset($form['name']);
    unset($form['pass']);
    unset($form['actions']);
    if (isset($form_state['step2'])) {
      $form = signin_step2_form($form, $form_state);
      return $form;
    }
    $form['mail'] = [
      '#title'       =&gt; t('Email'),
      '#description' =&gt; t('Enter your Email'),
      '#type'        =&gt; 'textfield',
      '#required'    =&gt; 'true',
      '#maxlength'   =&gt; 40,
    ];
    $form['next'] = [
      '#name'   =&gt; 'next',
      '#value'  =&gt; t('Next'),
      '#type'   =&gt; 'submit',
      '#submit' =&gt; ['signin_form_submit'],
    ];
    $form['#validate'] = ['signin_step1_form_validate'];
    return $form;
  }
}

function signin_step1_form_validate($form, &amp;$form_state) {
  $mail = $form_state['values']['mail'];
  if (empty(user_load_by_mail($mail))) {
    form_set_error('mail', t('The entered email is not associated with any account.'));
  }
}

function signin_step2_form($form, $form_state) {
  $form['pass'] = [
    '#title'       =&gt; t('Password'),
    '#description' =&gt; t('Enter the password'),
    '#type'        =&gt; 'password',
    #required' =&gt; 'true',
  ];
  $form['signin'] = [
    '#name'   =&gt; 'signin',
    '#value'  =&gt; t('SignIn'),
    '#type'   =&gt; 'submit',
    '#submit' =&gt; ['signin_form_submit'],
  ];
  $form['#validate'] = ['signin_step2_form_validate'];
  return $form;
}

function signin_step2_form_validate($form, &amp;$form_state) {
  $mail = $form_state['stored_values']['mail'];
  $user_obj = user_load_by_mail($mail);
  $name = $user_obj-&gt;name;
  $pass = $form_state['values']['pass'];
  if (!user_authenticate($name, $pass)) {
    form_set_error('pass', t('The Password you entered is incorrect'));
  }
}

function signin_form_submit($form, &amp;$form_state) {
  if ($form_state['clicked_button']['#name'] == 'next') {
    $form_state['step2'] = TRUE;
    $form_state['stored_values']['mail'] = $form_state['values']['mail'];
    $form_state["rebuild"] = TRUE;
  }
  else {
    $mail = $form_state['stored_values']['mail'];
    $user_obj = user_load_by_mail($mail);
    $form_state['uid'] = $user_obj-&gt;uid;
    user_login_submit($form, $form_state);
  }
}