I want to hook into the registration module. I already have a database of 50000 users who use my old website. Now I am migrating to Drupal.
I still haven't migrated the entries to drupal database. I will be checking against my old database.
When a user tries to register in Drupal, I need to check whether the username he gave is already present in that list of 50000 (and growing) entries. If it exists, I need to cancel the registration showing an error msg saying username exists..
Which hook should I use? If my code figures that the validation failed, How can I tell drupal to display an error msg?
Edit: I hooked into the hook_user and checked for the 'validate' op. I am able to validate and assign error messages. But it is happening for all forms. I want to validate only the new account creation form. How can I do that?
Thanks.
You should register an additional validation callback function for the registration form using
hook_form_FORM_ID_alter()
, somewhat like so:Here are some examples for Drupal 7:
Consider using the Username Originality AJAX check module: https://www.drupal.org/project/username_check
Henrik Opel answer work on Drupal 6. For Drupal 7 use yourModuleName_form_user_register_form_alter