Odd behaviour on form validation when in block mode Hi gurus and fellows, 

I have to generate an application form, that needs to be displayed both a as "page" (hook_menu) and as "block". 

I factorized the form generation within the same function (generate_form). It works fine, except for the validation process. Clearly the validation happens (form is not submitted when it fails), but the form_set_error() is never displayed  in block mode (in page mode, it works fine).  

This "lack of display" also happens for regular validation ('#required'=>'true'), so I don't think my custom validation code is at stake :  


When in page mode, the required fields get highlighted, the error
message is displayed.
When in block mode, the required fields get highlighted (red-bordered), BUT the error message is NOT displayed. 


Of course, I checked that the page.tpl.php, used to display the block, has a 'message' section, within it. Proof is my drupal_set_message() gets displayed on submit. 

Oddly enough, when I put a drupal_set_message() within my custom validation function, it gets displayed, as long as (and only when) the validation passes ! Wierd...

I pasted the *.module code here :  http://pastebin.com/cnwzp3UU 

Any idea ?
Taking a bit of a stab in the dark here, but I'm suspicious of this comment in your linked code right above hook_block_view():

// used in node--landing-page.tpl.php


That suggests that you're calling this block in directly from a template file, not through the normal block system, which won't work properly.

The problem is that the template files are built too late in the page build, in this case after the system messages have already been taken from the session and cleared out for the next page. So the validation messages do get added to the messages array in the session, but they won't be outputted until the next page is loaded.

I would suggest instead implementing hook_node_view() and adding your block into the content there. That hook is run early enough on in the page build that you won't see the delay with error messages.