How to make user email optional when registering with drupal 7?

How to make user email optional (optional) when registering with drupal 7?

+3
source share
4 answers

I was able to create my own module. It really looks like sharedemail.

<?php
function noemail_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  noemail_form_user_account_form_alter($form, $form_state, $form_id);
}
function noemail_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
  noemail_form_user_account_form_alter($form, $form_state, $form_id);
}
function noemail_form_user_account_form_alter(&$form, &$form_state, $form_id) {
  if (is_array($form['#validate'])) {
    $key = array_search( 'user_account_form_validate', $form['#validate'], TRUE );
    if ( $key !== FALSE ) {
      $form['#validate'][$key] = 'noemail_account_form_validate';
    }
  }
    $form['account']['mail']['#required'] = FALSE;
}
function noemail_account_form_validate($form, &$form_state) {
    $form['account']['mail']['#needs_validation'] = false;
}

and installation file if clicked

<?php
function sharedemail_install() {
  db_query("UPDATE {system} SET weight = -99 WHERE name = 'noemail'");
}

Hope this helps, wow, this is a really old thread. Oh and note that this is for d7

+2
source

You cannot change another check hook.

What you could try to do is create your own validation and on this form validation (['#validate']) the array will only create your own validation hook.

+1
source

There is an optional email module that makes the email field optional during user registration. Visit https://www.drupal.org/project/optional_mail , hope this helps.

+1
source

You can override # the required setting in the field using the API form inside the custom module with hook_form_alter .

0
source

All Articles