function contact_category_edit_form_validate

Form validation handler for contact_category_edit_form().

See also

contact_category_edit_form_submit()

File

modules/contact/contact.admin.inc, line 139

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.