0

The questions is very simple and the task is difficult. Which functions I need to create a new login form from scratch in Drupal 7?

The reason I need this is because I modified the default login form. It connects to a web service with two different methods and it has different validates, depends from a user roles and lots of customized stuff.

Right now to login as admin, I have to comment my custom module, so I can use the default login form.

I need to create a new login form on different page that will be dedicated to admin user.

  • When you say you "modified the default form", do you mean the real one or you just edited a copy, and made it accessible trough a path like "mymodule/login"? – Astrayus Feb 14 '14 at 23:41
2

It's not going to be possible to list all of the functions involved as your mileage will vary depending on what you need to do.

Basic steps:

  1. Read up on and understand the Form API; try out a few examples so you're familiar with it.
  2. Create a form function in your module, to be delivered in whatever method makes sense (a menu callback or embedding directly, for example). This will involve using drupal_get_form(), and viewing the user login form code will be useful here.
  3. Create a validate handler for the form which does any validation you need. See user_login_default_validators() for the login form defaults.
  4. Make use of user_login_finalize() in your form's submit handler to log the user in. You'd be best off copying the logic from user_login_submit() almost directly.
  • Thank you, Clive for the great answer. I know how to work with Form API, page callbacks, validators and drupal_get_form, so I'm on to the 4th point. I hope this thread will be useful for others that will try to accomplish a custom login form from scratch...thanks again. – user2519032 Feb 15 '14 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.