Drupal 7 Redirect after First and Later Login
In many cases you may need to take in extra information from user and display some type of graph after registration which cannot be fulfilled by adding extra fields within the form. In other way we can redirect to a second page containing your required form. In your module you need to write the following code for redirection for first time login after registration –
function yourmodule_form_alter(&$form, &$form_state,$form_id) { switch ($form_id) { case 'user_register_form': $form['#submit'][] = 'yourmodule_user_register_submit'; break; } } function yourmodule_user_register_submit($form, &$form_state) { $getuser = $form_state['values']['name']; $form_state['redirect'] = 'secondform'; }
For redirection to a particular page after login irrespective of first or other times.
/** * Implements hook_user_login(). */ function yourmodule_user_login(&$edit, $account) { if ($account->access > 0) { /* Execute code (for example redirect to user edit page). */ $_GET['destination'] = 'userdashboard'; } }
I have implemented this in Drupal 7 and its running successfully in this version. Thanks to my friend Santosh who helped me with this code. So there goes drupal 7 redirect after first and later login. Snippet for First and Later Login in Drupal 7.
Debdatta has more than 13 years in IT induustry and software engineering. Currently 6 years in data science, and machine learning. She holds a Master of Computer Applications degree and Executive Post Graduate Program Degree in Data Science. She is passionate about research, data-driven decisions, and technology’s role in business growth.