Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By DrupalFrank on
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
Solved with fix to page.tpl.php in my theme folder
I'm using a custom theme where the page.tpl.php did not print the $messages value. Now seems to work.
snippet?
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;
Worked for me!
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
Thanks! This worked for me.
Thanks! This worked for me. Just added it to my custom template file.
For Drupal 8
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?
Default behavior of drupal_get_messages
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.
I can tell you from personal
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
In my case it was the login
In my case it was the login_security module configuration, option was ticked to disable messages.