2

On registration we have to look up the user-information in a remote database (JSON service), when user is not found there, or when some other error occurs, we want to halt the registration completely.

function foo_user_presave(&$edit, $account, $category) {
  $foo_bar = new FooBarSource($edit["foo_bar_invite_code"]);
  if ($foo_bar->is_valid()) {
    drupal_set_message(t('Fail'), 'error');
    //What now?
  }
}

Problem is that I fear some records are being written already in, or before hook_user_presave. From the documentation:

A user account is about to be created or updated.

Is it safe to simply do a drupal_goto() to halt the registration? Would that cause orphaned records in the Database? What about other modules implementing this hook: would they break or be confused?

Is this hook the proper hook to determine if a user can register?

1 Answer 1

5

Do hook_form_alter for user registration form, and add extra validation function to the form using #validate like below.

$form['#validate'][] = 'extra_user_validation';

in function extra_user_validation set error after validation. So, that you can avoid the submit process and invoking hooks.

function extra_user_validation($form, &$form_state) {
   // Get the input values of registration form from $form_state['values']
   // Do validation & set error
}

That should work !

1
  • 1
    You must user form_set_error to set the error and cancel the changes.
    – user11348
    Commented Nov 12, 2012 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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