The default behavior for user registration is that if a user tries to register with an email that already exists, it lets them know and asks if they have forgotten their password.

We have a custom link to our product download in the email the user receives, and what we'd like to do if a user tries to re-register with the same email is to just resend the email, without notifying them that they already have an account.

I can't seem to find a way to do this. Any ideas? I'm not super-experienced with Drupal anymore.


function create_vector_user_form_user_register_form_alter(&$form, &$form_state) {
    error_log("form alter"); // this logs
    $form_state['values']['pass']['pass1'] = 'password';
    $form_state['values']['pass']['pass2'] = 'password';
    $form_state['values']['op'] = t('Create new account');
    $form['#submit'] []= "create_vector_user_user_register_submit";

function create_vector_user_user_register_submit($form, &$form_state) {
    error_log("submit handler"); // this does not log
  $form_state['build_info']['args'] = array(&$object);
  drupal_form_submit('create_vector_user_form', $form_state);
  drupal_set_message("The form is being submitted, do some extra stuff now...");

1 Answer 1

 * Implements hook_form_BASE_FORM_ID_alter().
function mymodule_form_user_register_form_alter(&$form, &$form_state, $form_id) {

  array_unshift($form['#validate'],'my_first_custom_validation' );
  $form['#validate'][] = 'my_last_custom_validation';


function my_first_custom_validation(&$form, &$form_state){
    if($user = user_load_by_mail($form_state['values']['mail'])){
      rules_invoke_component('rules_send_email_to_user', $user);
  1. Hook into register form using hook form alter
  2. Add custom validation handler to the top of submit handlers (must execute first before any other submit handler )
  3. In the handler function try to load user by email using user_load_by_mail If true send the email using drupal_mail or rules then redirect to same page or any page to stop the execution.

The only problem with this code that the validation error still showing , I could not find way to stop drupal from execute the rest of validation handlers

  • Thanks. I may need a bit more help. I've added my code based on your suggestions to the OP. The form_alter is being called, but the submit function never seems to hit.
    – EmmyS
    Commented Oct 1, 2015 at 15:36
  • I think you cant do this with submit handler you need to use the validation, I basically test that and its work , but I have one problem with removing error messages, I need way to stop the execution of the rest of validation callback from my custom validation
    – Ziftman
    Commented Oct 2, 2015 at 5:50

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.