1 contact.admin.inc | contact_category_edit_form_validate($form, &$form_state) |
Form validation handler for contact_category_edit_form().
See also
contact_category_edit_form_submit()
File
- core/
modules/ contact/ contact.admin.inc, line 370 - Admin page callbacks for the Contact module.
Code
function contact_category_edit_form_validate($form, &$form_state) {
// 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'];
// Get Categories Data.
$config_data = contact_config_data();
$categories = $config_data['categories'];
if ($categories) {
foreach ($categories as $cat) {
if ($form_state['values']['cid'] != $cat['cid'] AND $category == $cat['category']) {
if (empty($form_state['values']['cid'])) {
form_set_error('category', t('A contact form with category %category already exists.', array('%category' => $category)));
}
}
}
}
// Get addresses separated by comma, space, line break or semicolon.
$recipients = preg_split("/( |,|;|\n)/", $form_state['values']['recipients']);
// Cleanup addresses list.
$recipients = array_filter(array_map('trim', $recipients));
// Check recipients are valid email.
$invalid_recipients = array();
foreach ($recipients as &$recipient) {
if (!valid_email_address($recipient)) {
$invalid_recipients[] = $recipient;
}
}
if (!empty($invalid_recipients)) {
$message = format_plural(sizeof($invalid_recipients), '%recipient is an invalid email address.', 'The following email addresses are invalid: %recipient.', array('%recipient' => implode(', ', $invalid_recipients)));
form_set_error('recipients', $message);
}
// Force multiple addresses to be comma separated.
$form_state['values']['recipients'] = implode(',', $recipients);
// Store $config_data in $form_state for use in form_submit().
$form_state['categories_data'] = $config_data;
}