1

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.

Thanks

  • It's harder to help when we don't know your Drupal version. – No Sssweat May 3 '16 at 4:35
  • @NoSssweat Sorry. I'm using Drupal 7 – user2574948 May 3 '16 at 5:57
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? – user2574948 May 3 '16 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 '16 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. – user2574948 May 3 '16 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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