You are here

function reroute_email_element_validate_addresses in Reroute Email 7

Validate multiple email addresses field.

2 string references to 'reroute_email_element_validate_addresses'
reroute_email_settings in ./reroute_email.admin.inc
Settings form.
reroute_email_variable_type_info in ./reroute_email.variable.inc
Implements hook_variable_type_info().

File

./reroute_email.module, line 327
Intercepts all outgoing emails to be rerouted to a configurable destination.

Code

function reroute_email_element_validate_addresses($element, &$form_state, $form) {
  $field_name = $element['#name'];

  // Allow only valid email addresses.
  $addresses = reroute_email_split_string($form_state['values'][$field_name]);
  foreach ($addresses as $address) {
    if (!valid_email_address($address)) {
      form_set_error($field_name, t('@address is not a valid email address.', array(
        '@address' => $address,
      )));
    }
  }

  // Save value in usable way to use as `to` param in drupal_mail.
  // String "email@example.com; ;; , ,," save just as "email@example.com".
  // This will be ignored if any validation errors occur.
  form_set_value($form[$field_name], implode(',', $addresses), $form_state);
}