0

This is a weird issue. I have a custom theme which prints the login form (or user registration):

$form = drupal_get_form("user_login"); 
$user_menu = drupal_render($form);     

This works fine, and logs me in. However when I enter faulty data and submit no messages are shown. Upon dumping the $messages array I can see that each request actually generates two distinct logs. The first one is empty and the second is populated with the contents I require. If I F5 on the page, the messages show as expected. Obviously this won't work for end users. :)

Anyone encounter any issue like this before?

I do not have any third party login modules or actions/triggers set up...it's a fairly bare bones install. Very confused/frustrated.

EDIT | This sounds similar (drupal_get_messages always blank)

EDIT2 | I am using a sub-theme of the bootstrap theme if this makes any difference.

Alex

7
  • The post you linked to is definitely the problem - you need to prepare your form in a preprocess function. If you call drupal_get_form() in a template file, this is pretty much always what happens
    – Clive
    Mar 28, 2014 at 16:44
  • Prepare my form how? Why is printing the form directly as opposed to relying on the user/login different? If I use the "content" version of the form it works fine only when I print the form does this occur Mar 28, 2014 at 16:50
  • 1
    Read the answer to the linked duplicate, it explains fully what's happening. By "prepare form" I literally mean you need to do $vars['foo'] = drupal_get_form('bar'); in the preprocess function, not in the template file. Rendering in the template file is fine, though
    – Clive
    Mar 28, 2014 at 16:51
  • so the page is already built and thus $messages has been rendered and cleared. I get that. But I log the calls to drupal_set_message() when submitting a user/register form and I get three entries (one blank, username required, email required). So my page is rendering before the population of the latter two??? Mar 28, 2014 at 17:09
  • Sorry, one more question (I hope) in the preprocess function I have to basically fetch the messages and store them in a custom variable? That custom variable then replaces $messages? I'm failing to understand why this is required...I guess is what I'm asking. Mar 28, 2014 at 17:13

0

Browse other questions tagged or ask your own question.