2

I need to allow users to register for a Drupal-6 site, but only if their email contains a specific domain. For example, only allow users with whatever.com in their email address to register; a user with the email bob@whatever.com can register for the site, but bob@something.com cannot register for the site.

Is there a module for this? If not, which file would the PHP need to be altered for this?

  • Just throwing this out there - this can be accomplished through the Rules module. – Jukebox Sep 24 '11 at 20:55
1

the "user restrictions module" is supposed to offer that feature. But it doesn't seem ready for production yet. However you could use the code to write your own.

I also tried to do it with the rules module and setup a rule for the "event" "user: before saving account" with a condition "data comparison" on field "account:mail". Add "value contains" and use "@whatever.com" and then check the "negate" box. That will basically trigger the rule for all emails that don't contain @whatever.com.

However I couldn't find a way to stop the username from getting saved. If you use the event "user: after saving account" you can show an error to the user and block the account. It prevents the registration but shows a second message to your user "you'll get notified by the administrator". Not a great experience for your customers.

| improve this answer | |
0

I just wrote a hook to do something similar:

function MYMODULE_form_user_register_form_alter(&$form, $form_state, $form_id) {
  if (!($form_id == 'user_register_form')) {
    return;
  }

//if form is submitted validate the input
if ($form_state['method'] == 'post' && isset($form_state['input']['name']) ){

  $username = $form_state['input']['name'];
  if (strlen($username) < 5 || strlen($username) > 20) {
    $error_msg = t('The username has to be between 5 and 20 characters long. ');
    form_set_error('name', $error_msg);
| improve this answer | |

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.