Reputation: 31
How to make user email non-required (optional) upon registration in drupal 7?
Upvotes: 3
Views: 2081
Reputation: 21
There is a optional mail module that makes the email field optional in user registration. Visit https://www.drupal.org/project/optional_mail , I hope it helps.
Upvotes: 1
Reputation: 54
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
Upvotes: 2
Reputation: 11
You can't really change another validation hook.
What you could try to do is build your own validation and on that form's validation (['#validate']) array only instantiate your own validation hook.
Upvotes: 1
Reputation: 9809
You could override the #required setting on the field using the Form API inside of a custom module with a hook_form_alter implementation.
Upvotes: 0