Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make user email non-required upon registration in drupal 7?

How to make user email non-required (optional) upon registration in drupal 7?

like image 346
Sparko Avatar asked Nov 22 '25 07:11

Sparko


1 Answers

I was able to make a custom module. It's really similar to 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 the install file in case it's key

<?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 this is for d7

like image 146
SDMulroy Avatar answered Nov 24 '25 11:11

SDMulroy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!