[Drupal] How to register a new user using a custom form in Drupal 6?
This article is about creating a user using a separate registration page other than the default registration page in Drupal. I had done this when I faced a requirement to have a separate registration page for some special users.
For implementing this, I created a new form function 'registration_signup_form' and related functions for form validation, submission and theming. In the form, I added three fields, for username, email address and password. I added the form validation function 'registration_signup_form_validate' to validate these three fields. I wrote the function 'registration_signup_form_submit', the form submit handler. In this submit handler, I added an array, which stores the details of the user; ie., username, email address. You can also add other necessary information about the user in this array. I checked whether a user with this 'username' already exists or not, using user_load() function. If there is no user with that username, you can save the user information stored in the array. This is done using user_save() function. If you wish to move to the user's page you can redirect it using drupal_goto() function.
I created a menu for accessing this form by adding a new menu in the menu hook implementation function. I gave a drupal_get_form() in the page callback of the menu and the form function's name is given as page arguments. There is a function named 'user_register_access' which is defined inside the user module. This will check whether the user has authority to register. This function name is needed to be given in the access callback of the menu.
When you access the menu you have created in the menu hook function, you will get the new signup form. There you can add the user details and submit the form. A new user will be created.
Note: I am attaching a simple module to demonstrate this. Please see the attached file.
Attachment: registration.tar.gz