You are here

function smtp_admin_settings_validate in SMTP Authentication Support 6

Same name and namespace in other branches
  1. 7.2 smtp.admin.inc \smtp_admin_settings_validate()
  2. 7 smtp.admin.inc \smtp_admin_settings_validate()

Validation for the administrative settings form.

Parameters

form: An associative array containing the structure of the form.

form_state: A keyed array containing the current state of the form.

File

./smtp.module, line 225
Enables Drupal to send e-mail directly to an SMTP server.

Code

function smtp_admin_settings_validate($form, &$form_state) {
  if ($form_state['values']['smtp_on'] == 1 && $form_state['values']['smtp_host'] == '') {
    form_set_error('smtp_host', t('You must enter an SMTP server address.'));
  }
  if ($form_state['values']['smtp_on'] == 1 && $form_state['values']['smtp_port'] == '') {
    form_set_error('smtp_port', t('You must enter an SMTP port number.'));
  }
  if ($form_state['values']['smtp_from'] && !valid_email_address($form_state['values']['smtp_from'])) {
    form_set_error('smtp_from', t('The provided from e-mail address is not valid.'));
  }

  // If username is set empty, we must set both username/password empty as
  // as well.
  if (empty($form_state['values']['smtp_username'])) {
    $form_state['values']['smtp_password'] = '';
  }
  elseif (empty($form_state['values']['smtp_password'])) {
    unset($form_state['values']['smtp_password']);
  }
}