form_set_error message delayed one page refresh I'm making a custom validation in a form I'm making but my error message is always delayed by one page refresh.

$form['submit']['#validate'][] = 'asap_sollicitation_form_validate';


function asap_sollicitation_form_validate($form, &amp;$form_state)
{
    if(strlen($form_state['values']['pass']) &lt; 6){
        form_set_error('pass', t('Must be longer than 6'));
    }   
}


It successfully marks the field in red but the message is delayed. If I use only drupal_set_messsage without the form_set_error I do get a message displayed in time.
I render my form in a node template:

$arr = drupal_get_form('asap_sollicitation_form');
print drupal_render($arr);


How can I get my message to display after form submit?
I had the same, here is the solution and explanation:
The key of this problem is the drupal_get_form('FOO') is called in theme layer. For example _preprocess_WHATEVER or directly in BAR.tpl.php

The messages are prepared in _process_page()  After that it's unchangeable in deeper theme functions, like FOO_preprocess_node. (That's not exactly true, but it's out of scope of this topic.)

I bet, you prepared a variable by drupal_get_form('FOO') in _preprocess_node, maybe later.

You should use hook_entity_view_alter or hook_node_view_alter, maybe hook_page_alter if necessary, anything else than theme hooks.

Just for the record: The last time you are able to set a message by drupal_set_message() is _preprocess_page