You are here

function mailing_list_subscription_form_validate in Mailing List 7

Same name and namespace in other branches
  1. 6 mailing_list.module \mailing_list_subscription_form_validate()

Validation handler for the subscription form; checks name and e-mail entered.

1 string reference to 'mailing_list_subscription_form_validate'
mailing_list_subscription_form in ./mailing_list.module
Display a form letting a user subscribe to a mailing list.

File

./mailing_list.module, line 460
Minimalistic mailing list module.

Code

function mailing_list_subscription_form_validate($form, &$form_state) {
  $is_edit = FALSE;
  if (user_access('administer mailing lists')) {
    $admin = TRUE;
    $is_edit = !empty($form_state['values']['eid']);
  }
  $message = user_validate_mail($form_state['values']['mail']);
  if ($message) {
    form_set_error('mail', $message);
    return;
  }

  // Only do this check if the eid is not provided or the user is not an admin (and hense cannot edit existing entries).
  if (!$is_edit) {
    if (mailing_list_email_get_by_email($form_state['values']['mlid'], $form_state['values']['mail'])) {
      form_set_error('mail', t('The e-mail %mail already exists in mailing list %name.', array(
        '%mail' => $form_state['values']['mail'],
        '%name' => $form_state['values']['ml_name'],
      )));
    }
  }
}