function contact_category_edit_form_validate in Contact 7.2
Same name and namespace in other branches
- 6.2 contact.admin.inc \contact_category_edit_form_validate()
Validate the contact category edit page form submission.
File
- ./
contact.admin.inc, line 122 - 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);
}