如何在drupal 7中注册时不需要用户发送电子邮件?

时间:2011-05-10 08:54:28

标签: drupal drupal-7 registration

如何在drupal 7中注册时不需要用户发送电子邮件(可选)?

4 个答案:

答案 0 :(得分:2)

我能够制作自定义模块。它与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;
}

以及安装文件以防万一

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

希望这会有所帮助,哇,这是一个非常古老的主题。哦,注意这是d7

答案 1 :(得分:1)

你无法真正改变另一个验证钩子。

您可以尝试做的是构建自己的验证,并在该表单的验证(['#validate'])数组中仅实例化您自己的验证挂钩。

答案 2 :(得分:1)

有一个可选的邮件模块,可以在用户注册时使电子邮件字段成为可选项。访问https://www.drupal.org/project/optional_mail, 我希望它有所帮助。

答案 3 :(得分:0)

您可以使用#required setting实施的自定义模块中的Form API覆盖字段上的hook_form_alter

相关问题