Hi,
I have created a login block to be displayed on my home page.. using a custom module..

I have performed authentication validations inspired from user_auth module.
The problem i am facing is,

using form_set_error() display error messages. but submitting the form for the first time reloads the page but doesnt display the error messages
In short the validation is performed but error messages does not show up, on clicking the button again I do get the messages displayed properly i.e refreshing the page displays error messages.

Please provide some input as this is required urgently and it being the home page its quite frustrating for the client as well..

Thanks
hopin for an early reply

Comments

efarseer’s picture

I faced the issue too.

efarseer’s picture

Hi, I'm facing this issue too. I'm debug a lot, but don't know how to resolve this. Anyone can help me? Thanks a lot!!!!!

p_munshi’s picture

I am using the simplenews module. When I enter a wrong / invalid email address the field does turn red and the operation does terminate (so validation is being done), but no error message is printed. I know the simplenews.module uses form validate for entry of valid email and form_set_error() to set the message "The mail address you supplied is not valid". But somehow it does not display it. I am using drupal 6.

revnoah’s picture

I'm facing this too at the moment. It would've been nice if you'd followed up with a response at some point.

ShedPhotons’s picture

Could be Messages are disabled under the appearance tab or otherwise in CSS. Other troubleshooting tips: make sure variables agree between form and validation; compare syntax with a module where this is working.

knsheely’s picture

I have created a custom module to display the user view page with separate forms to edit certain fields attached with the user. I am am having the same problem where my validation stops the form from being submitted and the fields that have failed validation are highlighted, but no messages show. When I reload the page or submit the form again, the messages then show up. Has anyone figured out the problem here?

Note: This is not a $messages not being printed problem as the messages do show up once the page is reloaded a second time.

Jaypan’s picture

Code?

sanjeev.chadha’s picture

Hi All,
I could figure out the issue myself.. what I had done was used a block hook for having code for login in my module and mistakenly also added the same block of code in my template. which was like having the same block over the existing block from module again.. so form submit use to take place error use to be there but on refresh showed up the template page then

Solution: Just have either the module block or block in template...

hope this helps.

snehamay’s picture

I have faced this issue recently while migrating a D6 site to D7. Although I found that this discussion had started in long back, I would like to highlight the root cause of this issue, so that, who ever face the same issue can easily get retrieve from it.

This issue will come if we use drupal_get_form() function directly in any specific template file, because the template file is getting loaded before generating validation message after button click. This message will keep alive (as it is stored in $_SESSION) in the system until it gets printed. That's why for the next reload, variable $message prints the message in the template file.

To overcome from this issue, you have to create a block (ignore if the block is already created) and assign the block in required region (create a region in the theme info file if required). You can also use hook_form_alter() if needed.

Jaypan’s picture

Forms shouldn't be called in template files. They should be called in a preprocess function, and assigned to a variable that is then outputted in the template file.

ashwinparmar’s picture

Problem Statement:

Rendering custom login block using

$user_form = drupal_get_form('user_login_block');

and Print object of

$user_form

form. it will not print first time error message when user/pass was wrong or not found in database.

Solution:

Create object of user_login form instead of user_login_block.

$user_form = drupal_get_form('user_login');
print render($user_form);

It will works fine!

Shanmugarajank’s picture