I have a Drupal 7 form, built by using Form API. I just want to validate using the hook_form_validate function, and if there are errors, display them using drupal_set_message. It is working perfectly. The problem is that in another page, I have the same form in a div, in the left side of the page, and would want the error message to appear in this region only, and not at the top of the page, where now it is appearing (that is controlled in page.tpl.php via $message variable, I think). Any idea of how could I achieve this easily?

2 Answers 2


Inline Messages

The Inline Messages module allows you to move form messages (error/status/warning) from the top of the page to just above where your form appears.

I think this module may suit your needs.


If you use the form_set_error function instead of drupal_set_message, then the error message will be displayed within the form, which would mean that it would display inside your block.

If you would like to retain the drupal_set_message behaviour for your main form page then you would either need to differentiate which method is called in the validation based on url (or Context), or provide two separate forms so that you can simply validate each separately. In this instance you could build form and validate using a shared function to avoid duplication.

Your Answer

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

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