This blog describes about how to redirect users after logged into a site in Drupal 7. By default, Drupal redirects users to user page after logged into a site. Suppose you want to redirect users into any other pages as you want. Then you can done that in Drupal 7.
You can redirect users after login in Drupal using the following two ways:
1. Redirect users after logged into a site using hook_user_login()
2. Redirect users after logged into a site using custom form submit
Drupal provides hook called hook_user_login to make changes while user login successfully. Let see the below code.
Now you can check whether you redirect to front page or not after login. Now Drupal will be redirect you to front page.
Drupal have alternate method to redirect users after login. Ie, You need to add custom form submit handler to a form using hook_form_alter(). Then add a page to redirect users in that custom form submit handler in Drupal 7. Let see the below code.
/**
* Implement hook_form_alter().
*/
function phponwebsites_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == "user_login" || $form_id == "user_login_block") {
$form['#submit'][] = 'phponwebsites_custom_login_submit';
}
}
function phponwebsites_custom_login_submit(&$form, &$form_state) {
//page to be redirect
$form['redirect'] = '<front>';
}
Now you will be redirect to front page after logged into a drupal site. Now I’ve hope you should know how to redirect users after logged into a site in Drupal 7.
You can redirect users after login in Drupal using the following two ways:
1. Redirect users after logged into a site using hook_user_login()
2. Redirect users after logged into a site using custom form submit
Redirect users after logged into a site using hook_user_login:
Drupal provides hook called hook_user_login to make changes while user login successfully. Let see the below code.
/**
* Implement hook_user_login()
*/
function phponwebsites_user_login(&$form, &$form_state) {
//add page here to where you want redirect users after login
$form['redirect'] = '<front>';
}
* Implement hook_user_login()
*/
function phponwebsites_user_login(&$form, &$form_state) {
//add page here to where you want redirect users after login
$form['redirect'] = '<front>';
}
Now you can check whether you redirect to front page or not after login. Now Drupal will be redirect you to front page.
Redirect users after logged into a site using custom form submit:
Drupal have alternate method to redirect users after login. Ie, You need to add custom form submit handler to a form using hook_form_alter(). Then add a page to redirect users in that custom form submit handler in Drupal 7. Let see the below code.
/**
* Implement hook_form_alter().
*/
function phponwebsites_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == "user_login" || $form_id == "user_login_block") {
$form['#submit'][] = 'phponwebsites_custom_login_submit';
}
}
function phponwebsites_custom_login_submit(&$form, &$form_state) {
//page to be redirect
$form['redirect'] = '<front>';
}
Now you will be redirect to front page after logged into a drupal site. Now I’ve hope you should know how to redirect users after logged into a site in Drupal 7.
Related articles:
Add new menu item into already created menu in Drupal 7
Add class into menu item in Drupal 7
Create menu tab programmatically in Drupal 7
Add custom fields to search api index in Drupal 7
Clear views cache when insert, update and delete a node in Drupal 7
Create a page without header and footer in Drupal 7
Login using both email and username in Drupal 7
Add new menu item into already created menu in Drupal 7
Add class into menu item in Drupal 7
Create menu tab programmatically in Drupal 7
Add custom fields to search api index in Drupal 7
Clear views cache when insert, update and delete a node in Drupal 7
Create a page without header and footer in Drupal 7
Login using both email and username in Drupal 7
There is a contrib module which provides the similar functionality https://www.drupal.org/project/simple_redirect
ReplyDeletecanlı sex hattı
ReplyDeletesalt likit
heets
arkadaşlık sitesi
B8JB
şişli
ReplyDeleteavcılar
sakarya
elazığ
bursa
UL1
https://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
3B8
Grreat blog I enjoyed reading
ReplyDelete