0
votes

I have called a custom function on form submit of Drupal User Registration.

Below are the functions that i implemented

/**
 * Implements hook_form_alter()
 */
function voen_registration_form_alter(&$form, &$form_state, $form_id) {
  //dpm($form);
  switch($form_id){
    case 'user_register_form':
      $form['account']['name']['#required'] = FALSE;
      $form['account']['name']['#type'] = 'hidden';
      array_unshift($form['#submit'],'voen_generate_username');
      print_r($form);
      break;
  }     
}

function voen_generate_username(&$form, &$form_state){
  //drupal_set_message('Function Running');
  die('Wokring');  
}

Now, when the form is submitted i print_r the $form and in submit key i get the following result which is what i expect

 [#submit] => Array
        (
            [0] => voen_generate_username
            [1] => user_register_submit
        )

But I don't know why my custom function is not executing. I tried with die() as well se drupal_set_message() and also tried to print_r() in custom function but no response. It is still giving me error of 'Please Enter Username' which is comming from user_register_submit function from user module.

Thanks

1

1 Answers

1
votes

The submit function is not executed because the validation function is not passed. Take a look at $form['#validate'], there is an "user_account_form_validate" function which will not pass if you not define at least a default value for name field.

Anyway, if you're trying to allow registration only by email take a look at this module: https://www.drupal.org/project/email_registration