From 613398940f7e5745401e94c8d10cc7337144786b Mon Sep 17 00:00:00 2001 From: Pedro Cambra Date: Mon, 12 Sep 2011 12:05:11 +0200 Subject: [PATCH] Issue [#583152] by pcambra: Add a e-mail confirmation field on registration. --- email_registration.install | 13 +++++++++++ email_registration.module | 48 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 email_registration.install diff --git a/email_registration.install b/email_registration.install new file mode 100644 index 0000000..c3673c0 --- /dev/null +++ b/email_registration.install @@ -0,0 +1,13 @@ + 'textfield', + '#title' => t('Confirm e-mail address'), + '#weight' => -28, + '#maxlength' => 64, + '#description' => t('Please re-type your e-mail address to confirm it is accurate.'), + '#required' => TRUE, + ); + // Weight things properly so that the order is mail, conf_mail. + $form['account']['mail']['#weight'] = -29; + + // Add a validation routine to check if both addresses are the same. + $form['#validate'][] = 'email_registration_user_register_validate'; + } } else { $form['name']['#type'] = 'hidden'; @@ -93,11 +109,25 @@ function email_registration_form_alter(&$form, &$form_state, $form_id) { } } +/** + * Implements hook_form_FORM_ID_alter(). + */ +function email_registration_form_user_admin_settings_alter(&$form, &$form_state, $form_id) { + $form['email_registration'] = array( + '#type' => 'fieldset', + '#title' => t('Email registration settings.'), + ); + + $form['email_registration']['email_registration_confirmation'] = array( + '#type' => 'checkbox', + '#title' => t('Require e-mail confirmation when a visitor creates an account.'), + '#default_value' => variable_get('email_registration_confirmation', FALSE), + ); +} /** * Form element submit handler for user registration form - * Fixes redirect for immediate logins - * + * Fixes redirect for immediate logins. */ function custom_email_registration_name_submit($form, &$form_state) { if (!isset($form_state['user'])) { @@ -127,4 +157,14 @@ function email_registration_user_login_validate($form, &$form_state) { $form_state['values']['name'] = $name; } } -} \ No newline at end of file +} + +/** + * Form element validation handler for user registration form. + * Checks if the e-mail and confirmation e-mail addresses are the same. + */ +function email_registration_user_register_validate($form, &$form_state) { + if ($form_state['values']['mail'] != $form_state['values']['conf_mail']) { + form_set_error('conf_mail', t('Your e-mail address and confirmed e-mail address must match.')); + } +} -- 1.7.3.3