Hello,

I am developing a theme with both login and register forms on the homepage.

I face a problem with form validation: when I submits the login form with an invalid username, it also adds a red border for the username field of the register form.

I don't understand why this happens. Why the login validation affects my register form and not only the login form?

Thanks in advance for your help.

Comments

cayenne’s picture

If it really bothers you, you can probably create some little PHP form that renames the form on the page but reverts that field name to the original before submitting.

:)

jbarbede’s picture

Yes you are right Cayenne, it is the same field name on both forms.

But there is a strange comportment: if I submit the register form, the problem doesn't appear on the login form. I mean if I have an error on "name" field in register form, the "name" field in login form doesn't have the "error" class.

For your solution, I guess I have to unset the "name" field, add a "username" field for example to my login form alter, add validation on this field and on submit set the value of "username" field in "name" field.

Anonymous’s picture

My guess is that you have themed a class that is not specified to a particular form. Do you any additional information?

gooddesignusa’s picture

I also have the same problem. I was working on a slide down panel that would have both forms in it but got stuck when I ran into this issue. I asked on irc for a couple days and searched online but didn't find much. If you come up with a solution please contact me. Thanks a lot.

I really wish when it added the class of error to the input fields that it also added it to the parent form. This way it would just be a simple css fix. Instead of adding it to the field with the name "name"

Rizhaya’s picture

Subscribe

drscales’s picture

Easiest way is to use login toboggan, which changes the attributes of the register form, and team this with the Ajax module, for nice ajax validation. From what I read before this, it seems they don't behave in a standard way out of the Drupal box, but these modules fixed it for me.

Tech_Musings’s picture

Ajax module with login toboggan works great for separate the validation message though when click on login button it shows the error but it does not highlight the field.
any idea why the field not highlighted ?

mattcasey’s picture

If you want to add the forms together with hook_form_alter(), make sure you aren't altering the form when it's being submitted. See my post here for an example how I did it: http://drupal.org/node/404480#comment-5319696

drupsforyou’s picture

Follow the below steps:
1) Check whether the form name and form id is different for the registration and login page or not.
2) Check the hook_form is defined correctly.
3) Last but not the list is hook_form_alter.