I'm writing a custom module which will process information using an external service and need to display any errors thrown by this service.

I already have a variable containing error messages.

How can I target a page body markup to show the error message? I have tried hook_page_alter but failed not knowing if a page body can be processed at this stage.


  • It's harder to help when we don't know your Drupal version.
    – No Sssweat
    May 3, 2016 at 4:35
  • @NoSssweat Sorry. I'm using Drupal 7 May 3, 2016 at 5:57

1 Answer 1


You can use the Drupal message system.

Ex: drupal_set_message(t('Error message goes in here'), 'error');

In you case: drupal_set_message(t($yourvariable), 'error');

  • Thanks for the answer @NoSssweat However I'm targeting a different page. Therefore how can I call drupal_set_message in a specific page? May 3, 2016 at 6:17
  • I have never done that before. I believe the message shows up on whatever page you visit next, so you could try redirecting the user with drupal_goto() ex: drupal_goto("/node/1");
    – No Sssweat
    May 3, 2016 at 6:26
  • Sure I will try using drupal_set_message. The reason I can't use drupal_go_to is that I'm redirecting user already using 'Webform Confirm Email' module. This module has a field to enter page that needs user redirected after he/she validates email address. So originally I'm looking at displaying the error message on this page. May 3, 2016 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.