You are here

function contact_category_edit_form_validate in Drupal 7

Form validation handler for contact_category_edit_form().

See also

contact_category_edit_form_submit()

File

modules/contact/contact.admin.inc, line 139
Admin page callbacks for the Contact module.

Code

function contact_category_edit_form_validate($form, &$form_state) {

  // Validate and each e-mail recipient.
  $recipients = explode(',', $form_state['values']['recipients']);

  // When creating a new contact form, or renaming the category on an existing
  // contact form, make sure that the given category is unique.
  $category = $form_state['values']['category'];
  $query = db_select('contact', 'c')
    ->condition('c.category', $category, '=');
  if (!empty($form_state['values']['cid'])) {
    $query
      ->condition('c.cid', $form_state['values']['cid'], '<>');
  }
  if ($query
    ->countQuery()
    ->execute()
    ->fetchField()) {
    form_set_error('category', t('A contact form with category %category already exists.', array(
      '%category' => $category,
    )));
  }
  foreach ($recipients as &$recipient) {
    $recipient = trim($recipient);
    if (!valid_email_address($recipient)) {
      form_set_error('recipients', t('%recipient is an invalid e-mail address.', array(
        '%recipient' => $recipient,
      )));
    }
  }
  $form_state['values']['recipients'] = implode(',', $recipients);
}