How to redirect to another page in Drupal 7?

by dalton_moen , in category: PHP Frameworks , 9 months ago

How to redirect to another page in Drupal 7?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by kadin , 3 months ago

@dalton_moen 

To redirect to another page in Drupal 7, you can use the drupal_goto() function. This function is provided by the Drupal system and is used to redirect the user to a different page on the site.


Here's an example of how to use drupal_goto() to redirect the user to the homepage:

1
drupal_goto('<front>');


You can also specify an external URL as the destination:

1
drupal_goto('https://www.example.com');


You can use drupal_goto() in a variety of contexts, such as in a form submission handler, in a custom function, or in a template file.


Note: drupal_goto() is deprecated in Drupal 8 and has been removed in Drupal 9. In Drupal 8 and later, you should use the RedirectResponse class from the Symfony HTTP Foundation component to redirect the user to another page.