It is great that this module checks to see if a valid email address has been entered, but in many cases I have the need to request the user to enter their email address twice just to be sure they got it right. I have modified this module to incorporate this functionality:

the new
function email_widget($op, &$node, $field, &$node_field) {

function email_widget($op, &$node, $field, &$node_field) {
  switch ($op) {
    case 'form':
      $form = array();
      $form[$field['field_name']] = array(
        '#tree' => TRUE,
        '#weight' => $field['widget']['weight'],
      );

      if ($field['multiple']) {
        $form[$field['field_name']]['#type'] = 'fieldset';
        $form[$field['field_name']]['#title'] = t($field['widget']['label']);
        foreach (range(0,1) as $delta) {
          $default_value = "";
          if (isset($field['widget']['default_value'][$delta]['email'])) {
            $default_value = $field['widget']['default_value'][$delta]['email'];
          }
          $form[$field['field_name']][$delta]['email'] = array(
            '#type' => 'textfield',
            '#title' => '',
            '#default_value' => isset($node_field[$delta]['email']) ? $node_field[$delta]['email'] : $default_value,
            '#required' => $field['required'] ? $field['required'] : FALSE,
            '#maxlength' => 255,
            '#size' => isset($field['widget']['size']) ? $field['widget']['size'] : 60,
            '#description' => isset($field['widget']['description']) ? $field['widget']['description'] : '',
          );
        }
      }
      else if ($field['widget']['verify']) {
        $default_value = "";
        if (isset($field['widget']['default_value'][0]['email'])) {
          $default_value = $field['widget']['default_value'][0]['email'];
        }
        $form[$field['field_name']][0]['email'] = array(
          '#type' => 'textfield',
          '#title' => $field['widget']['label'],
          '#default_value' => isset($node_field[0]['email']) ? $node_field[0]['email'] : $default_value,
          '#required' => $field['required'] ? $field['required'] : FALSE,
          '#maxlength' => 255,
          '#size' => isset($field['widget']['size']) ? $field['widget']['size'] : 60,
          '#description' => isset($field['widget']['description']) ? $field['widget']['description'] : '',
        );

        // verification field
        $form[$field['field_name']][1]['email'] = array(
          '#type' => 'textfield',
          '#title' => 'Verify '.$field['widget']['label'],
          '#default_value' => isset($node_field[0]['email']) ? $node_field[0]['email'] : $default_value,
          '#required' => $field['required'] ? $field['required'] : FALSE,
          '#maxlength' => 255,
          '#size' => isset($field['widget']['size']) ? $field['widget']['size'] : 60,
          '#description' => isset($field['widget']['description']) ? $field['widget']['description'] : '',
        );
      }
      else {
        $default_value = "";
        if (isset($field['widget']['default_value'][0]['email'])) {
          $default_value = $field['widget']['default_value'][0]['email'];
        }
        $form[$field['field_name']][0]['email'] = array(
          '#type' => 'textfield',
          '#title' => $field['widget']['label'],
          '#default_value' => isset($node_field[0]['email']) ? $node_field[0]['email'] : $default_value,
          '#required' => $field['required'] ? $field['required'] : FALSE,
          '#maxlength' => 255,
          '#size' => isset($field['widget']['size']) ? $field['widget']['size'] : 60,
          '#description' => isset($field['widget']['description']) ? $field['widget']['description'] : '',
        );
      }

      return $form;

    case 'validate':
      if (is_array($node_field)) {
          foreach ($node_field as $delta => $item) {
            if ($item['email'] != '' && !valid_email_address($item['email'])) {
              form_set_error($field['field_name'],t('"%mail" is not a valid email address',array('%mail' => $item['email'])));
            }
          }
          if ($field['widget']['verify']) {
            if ($node_field[0]['email'] != $node_field[1]['email'])
              form_set_error($field['field_name'],t('"%mail" does not match %verify',array('%mail' => $node_field[0]['email'], '%verify' => $node_field[1]['email'])));
          }
      }
      break;
  }
}

the new
function email_widget_settings($op, $widget) {

function email_widget_settings($op, $widget) {
  switch ($op) {
    case 'form':
      $form = array();
      $form['size'] = array(
        '#type' => 'textfield',
        '#title' => t('Size'),
        '#default_value' => isset($widget['size']) ? $widget['size'] : 60,
        '#required' => FALSE,
        '#description' => t('Size of textfield'),
      );

      $options = array(
        'mailto' => t('Mailto: Direct link'),
        'form' => t('Contact form'),
      );
      if (module_exists('invisimail')) {
        $options += array('mailto_encrypt' => t('Mailto: Direct link with invisimail encryption'));
      }
      $form['link_type'] = array(
        '#type' => 'radios',
        '#title' => t('Email Link Type'),
        '#default_value' => isset($widget['link_type']) ? $widget['link_type'] : 'mailto',
        '#options' => $options,
      );

      $form['verify'] = array(
        '#type' => 'checkbox',
        '#title' => t('Verify Email Address'),
        '#default_value' => isset($widget['verify']) ? $widget['verify'] : '',
      );

      return $form;

    case 'validate':
      if (!empty($widget['size']) && (!is_numeric($widget['size']) || intval($widget['size']) != $widget['size'] || $widget['size'] <= 0)) {
        form_set_error('size', t('"Size" must be a positive integer.'));
      }
      break;

    case 'save':
      return array('size', 'link_type', 'verify');
  }
}

I know I really need to be doing those "diff" files for stuff like this but I haven't had the time to learn how to do that even though I am sure it is really simple.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kenorb’s picture

Version: 5.x-1.x-dev » 7.x-1.x-dev

+1
Similar request for Drupal 6.x: #1262256: Using email field to verify user...

Zombie777’s picture

Is it safe to incorporate this in the current version for D7 or does it need to be reviewed?

emarchak’s picture

Version: 7.x-1.x-dev » 7.x-1.2
FileSize
3.11 KB

Attached is a patch against the 7.x-1.2 branch. I've created a setting that asks if verification is required, and then exposed two sets of fields on the form with a verification check if they match.

Simple simple.

jlbellido’s picture

Version: 7.x-1.2 » 7.x-1.3
FileSize
2.98 KB

Added a new patch fixing somethings from the previous patch:

- FIxed : When we click at "verify" option the first time we aren't allowed to save the field settings because the email_verify isn't set in the field settings.

- Updated the previous patch to 7.1.3 version

Thanks a lot for this module and the previous work in this issue :D.

shortspoken’s picture

Tested the latest patch and it works as advertised! Thanks a lot! :)

jlbellido’s picture

RTBC?

kenorb’s picture

Status: Needs review » Reviewed & tested by the community
mariacha1’s picture

The first two lines of the included patch weren't in the right format to apply cleanly when using drush make, so I've updated them with the included patch with an interdiff to show what's changed (nothing in the code, just lines in the .patch file itself).

crutch’s picture

Thank you!

Wonder how to do instant feedback, "Matches" or "Does Not Match" for those with js enabled?

sgurlt’s picture

Tested #8 against latest dev, works pretty good :)

crutch’s picture

I got lost in modules and thought the verification field was a different module but in fact was this patch against the email field module. Here is an issue posted at wrong location regarding this patch. https://www.drupal.org/node/2716011

sgurlt’s picture

@Maintainer, could we please comit this to the latest dev version, looks stable :)