How do I redirect after saving the user account with $user->save()?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
How can I redirect users in a custom module after saving a user account with $user->save()
? It always goes to the user profile after saving and I want to redirect to a custom page.
function user_update_redirect(&$form, $form_state)
$value1 = $form_state->getValue('panel');
$value2 = $form_state->getValue('type_of_user');
$storage = Drupal::service('entity_type.manager')->getStorage('taxonomy_term');
$user = Drupal::currentUser();
$user = user_load($user->id());
$user->set('field_panel', $value1);
$user->set('field_type_of_user', $value2);
kint($user);
$user->save();
8 users redirect
add a comment |Â
up vote
1
down vote
favorite
How can I redirect users in a custom module after saving a user account with $user->save()
? It always goes to the user profile after saving and I want to redirect to a custom page.
function user_update_redirect(&$form, $form_state)
$value1 = $form_state->getValue('panel');
$value2 = $form_state->getValue('type_of_user');
$storage = Drupal::service('entity_type.manager')->getStorage('taxonomy_term');
$user = Drupal::currentUser();
$user = user_load($user->id());
$user->set('field_panel', $value1);
$user->set('field_type_of_user', $value2);
kint($user);
$user->save();
8 users redirect
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
How can I redirect users in a custom module after saving a user account with $user->save()
? It always goes to the user profile after saving and I want to redirect to a custom page.
function user_update_redirect(&$form, $form_state)
$value1 = $form_state->getValue('panel');
$value2 = $form_state->getValue('type_of_user');
$storage = Drupal::service('entity_type.manager')->getStorage('taxonomy_term');
$user = Drupal::currentUser();
$user = user_load($user->id());
$user->set('field_panel', $value1);
$user->set('field_type_of_user', $value2);
kint($user);
$user->save();
8 users redirect
How can I redirect users in a custom module after saving a user account with $user->save()
? It always goes to the user profile after saving and I want to redirect to a custom page.
function user_update_redirect(&$form, $form_state)
$value1 = $form_state->getValue('panel');
$value2 = $form_state->getValue('type_of_user');
$storage = Drupal::service('entity_type.manager')->getStorage('taxonomy_term');
$user = Drupal::currentUser();
$user = user_load($user->id());
$user->set('field_panel', $value1);
$user->set('field_type_of_user', $value2);
kint($user);
$user->save();
8 users redirect
8 users redirect
edited 1 hour ago


kiamlaluno♦
78.6k9125243
78.6k9125243
asked 1 hour ago
Ștefan Roman
83
83
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
I suppose you want to remain on your site when redirecting.
I don't recommend hardcoded URL's anywhere else but in route.yml files.
Call the right service and don't forget to use dependency injection in your services and don't use a trait or directly call it from the container.
private function redirect(string $route)
$path = $this->container->get('url_generator')->getPathFromRoute($route);
return new RedirectResponse($path);
add a comment |Â
up vote
1
down vote
After $user->save();
add
$url = '/some/path';
$response = new SymfonyComponentHttpFoundationRedirectResponse($url);
$response->send();
add a comment |Â
up vote
1
down vote
$form_state->setRedirectUrl(Url::fromUserInput($redirect_path));
New contributor
PHP is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Welcome to Drupal Answer! Thank you for your answer. Please try to elaborate it a bit. Why this snippet, how to use it, in what function, what is$redirect_path
? One-line answers don't provide that much of a value for future readers. Thanks! And keep up the good work.
– leymannx
2 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
I suppose you want to remain on your site when redirecting.
I don't recommend hardcoded URL's anywhere else but in route.yml files.
Call the right service and don't forget to use dependency injection in your services and don't use a trait or directly call it from the container.
private function redirect(string $route)
$path = $this->container->get('url_generator')->getPathFromRoute($route);
return new RedirectResponse($path);
add a comment |Â
up vote
2
down vote
I suppose you want to remain on your site when redirecting.
I don't recommend hardcoded URL's anywhere else but in route.yml files.
Call the right service and don't forget to use dependency injection in your services and don't use a trait or directly call it from the container.
private function redirect(string $route)
$path = $this->container->get('url_generator')->getPathFromRoute($route);
return new RedirectResponse($path);
add a comment |Â
up vote
2
down vote
up vote
2
down vote
I suppose you want to remain on your site when redirecting.
I don't recommend hardcoded URL's anywhere else but in route.yml files.
Call the right service and don't forget to use dependency injection in your services and don't use a trait or directly call it from the container.
private function redirect(string $route)
$path = $this->container->get('url_generator')->getPathFromRoute($route);
return new RedirectResponse($path);
I suppose you want to remain on your site when redirecting.
I don't recommend hardcoded URL's anywhere else but in route.yml files.
Call the right service and don't forget to use dependency injection in your services and don't use a trait or directly call it from the container.
private function redirect(string $route)
$path = $this->container->get('url_generator')->getPathFromRoute($route);
return new RedirectResponse($path);
answered 33 mins ago


ssibal
1,739518
1,739518
add a comment |Â
add a comment |Â
up vote
1
down vote
After $user->save();
add
$url = '/some/path';
$response = new SymfonyComponentHttpFoundationRedirectResponse($url);
$response->send();
add a comment |Â
up vote
1
down vote
After $user->save();
add
$url = '/some/path';
$response = new SymfonyComponentHttpFoundationRedirectResponse($url);
$response->send();
add a comment |Â
up vote
1
down vote
up vote
1
down vote
After $user->save();
add
$url = '/some/path';
$response = new SymfonyComponentHttpFoundationRedirectResponse($url);
$response->send();
After $user->save();
add
$url = '/some/path';
$response = new SymfonyComponentHttpFoundationRedirectResponse($url);
$response->send();
answered 1 hour ago


No Sssweat
19.1k73161
19.1k73161
add a comment |Â
add a comment |Â
up vote
1
down vote
$form_state->setRedirectUrl(Url::fromUserInput($redirect_path));
New contributor
PHP is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Welcome to Drupal Answer! Thank you for your answer. Please try to elaborate it a bit. Why this snippet, how to use it, in what function, what is$redirect_path
? One-line answers don't provide that much of a value for future readers. Thanks! And keep up the good work.
– leymannx
2 mins ago
add a comment |Â
up vote
1
down vote
$form_state->setRedirectUrl(Url::fromUserInput($redirect_path));
New contributor
PHP is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Welcome to Drupal Answer! Thank you for your answer. Please try to elaborate it a bit. Why this snippet, how to use it, in what function, what is$redirect_path
? One-line answers don't provide that much of a value for future readers. Thanks! And keep up the good work.
– leymannx
2 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
$form_state->setRedirectUrl(Url::fromUserInput($redirect_path));
New contributor
PHP is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$form_state->setRedirectUrl(Url::fromUserInput($redirect_path));
New contributor
PHP is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
PHP is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 13 mins ago


PHP
112
112
New contributor
PHP is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
PHP is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
PHP is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Welcome to Drupal Answer! Thank you for your answer. Please try to elaborate it a bit. Why this snippet, how to use it, in what function, what is$redirect_path
? One-line answers don't provide that much of a value for future readers. Thanks! And keep up the good work.
– leymannx
2 mins ago
add a comment |Â
Welcome to Drupal Answer! Thank you for your answer. Please try to elaborate it a bit. Why this snippet, how to use it, in what function, what is$redirect_path
? One-line answers don't provide that much of a value for future readers. Thanks! And keep up the good work.
– leymannx
2 mins ago
Welcome to Drupal Answer! Thank you for your answer. Please try to elaborate it a bit. Why this snippet, how to use it, in what function, what is
$redirect_path
? One-line answers don't provide that much of a value for future readers. Thanks! And keep up the good work.– leymannx
2 mins ago
Welcome to Drupal Answer! Thank you for your answer. Please try to elaborate it a bit. Why this snippet, how to use it, in what function, what is
$redirect_path
? One-line answers don't provide that much of a value for future readers. Thanks! And keep up the good work.– leymannx
2 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f270453%2fhow-do-i-redirect-after-saving-the-user-account-with-user-save%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password