Is there simply a function I should implement that would display the contents of form_get_errors()?

My form validates via *_validate(...) functions, but none of the "form_set_error'" messages are showing up.

Same thing with using "#required=TRUE" .... form stops submitting if value not provided, but NO error message is displayed.

Also, " $e=form_get_errors();" is returning an empty array in the function that "drupal_get_form" is calling.

Thanks in advance for any insight.

Comments

DrupalFrank’s picture

I'm using a custom theme where the page.tpl.php did not print the $messages value. Now seems to work.

ShedPhotons’s picture

Note - I had trouble with this - it turned out Messages were disabled in the subtheme. Check this under Appearance/Toggle Advanced Options.

And here's a snippet that will display them, if needed.

print $messages;

gurtner’s picture

Thanks, @ShedPhotons. I was having the same issue and all I needed was to add the <?php print $messages; ?> of my content region.

danielgurtner.com

ncbasecamp’s picture

Thanks! This worked for me. Just added it to my custom template file.

chintukarthi’s picture

I am Facing the same issue. Error messages isn't displaying in drupal 8 form. Can you explain where should i enter the print $message?

RAWDESK’s picture

We were experiencing a similar issue, but despite the useful comments here, it was not due to the fact the messages were not printed in the template.

Instead, we found that some contributing sandbox module (https://www.drupal.org/sandbox/tealium/2312413) was calling drupal_get_messages with arguments ('error'), which by default clears the message queue for the given type :
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drup...

In my opinion, the default behavior of this function should be without message clearance :
drupal_get_messages($type = NULL, $clear_queue = FALSE)
instead of drupal_get_messages($type = NULL, $clear_queue = TRUE)
to avoid unshown error messages.

Summarized: if for some reason you need to read out the messages, always give FALSE to the second function argument, to avoid message clearance.

dotmundo’s picture

I can tell you from personal experience that I totally agree with this as this has caused me complete frustration when trying to create a website to user requirements where they strictly specified the addition of inline error messages. The result of this led me to develop an alternative solution which I outlined in this thread several months ago.

https://www.drupal.org/node/2835888

alexgw’s picture

In my case it was the login_security module configuration, option was ticked to disable messages.