Drupal 7 – form_set_error does not show

I have a custom form and i render the form using drupal_get_form() inside the .tpl.php. One day, i find that when the submission could not pass the validation, only the failed field was highlighted but without the error message. Then i find the following post suggesting that i should called the drupal_get_form() in the .module file or preprocess function instead of the .tpl.php.
form_set_error Not displaying error after invalid form submission

So i put the drupal_get_form() call in the preprocess function and set the form in the $vars so it could be printed in the .tpl.php. But that still could not solve the problem. Finally i come up with a simple solution which is just adding the following line in the .tpl.php.

<div><?php print theme_status_messages(array('display' => 'error')); ?></div>


Done =)



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.