Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#8 | interdiff.txt | 318 bytes | mariacha1 |
#8 | email-verification_field-234682-8.patch | 2.85 KB | mariacha1 |
#4 | email-verification_field-234682-4.patch | 2.98 KB | jlbellido |
#3 | email-verification_field-234682-3.patch | 3.11 KB | emarchak |
Comments
Comment #1
kenorb CreditAttribution: kenorb commented+1
Similar request for Drupal 6.x: #1262256: Using email field to verify user...
Comment #2
Zombie777 CreditAttribution: Zombie777 commentedIs it safe to incorporate this in the current version for D7 or does it need to be reviewed?
Comment #3
emarchak CreditAttribution: emarchak commentedAttached 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.
Comment #4
jlbellidoAdded 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.
Comment #5
shortspoken CreditAttribution: shortspoken commentedTested the latest patch and it works as advertised! Thanks a lot! :)
Comment #6
jlbellidoRTBC?
Comment #7
kenorb CreditAttribution: kenorb commentedComment #8
mariacha1 CreditAttribution: mariacha1 commentedThe 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).
Comment #9
crutch CreditAttribution: crutch commentedThank you!
Wonder how to do instant feedback, "Matches" or "Does Not Match" for those with js enabled?
Comment #10
sgurlt CreditAttribution: sgurlt at Bright Solutions GmbH commentedTested #8 against latest dev, works pretty good :)
Comment #11
crutch CreditAttribution: crutch commentedI 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
Comment #12
sgurlt CreditAttribution: sgurlt at Bright Solutions GmbH commented@Maintainer, could we please comit this to the latest dev version, looks stable :)