How to make user email non-required upon registration in drupal 7?
How to make user email non-r开发者_如何学编程equired (optional) upon registration in drupal 7?
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
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.
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.
You could override the #required setting on the field using the Form API inside of a custom module with a hook_form_alter implementation.
精彩评论