diff options
Diffstat (limited to 'modules/contact')
-rw-r--r-- | modules/contact/contact.admin.inc | 12 | ||||
-rw-r--r-- | modules/contact/contact.test | 5 |
2 files changed, 17 insertions, 0 deletions
diff --git a/modules/contact/contact.admin.inc b/modules/contact/contact.admin.inc index 585d5f8a0..6677962a5 100644 --- a/modules/contact/contact.admin.inc +++ b/modules/contact/contact.admin.inc @@ -112,6 +112,18 @@ function contact_category_edit_form($form, &$form_state, array $category = array 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)) { diff --git a/modules/contact/contact.test b/modules/contact/contact.test index 02adc9709..b54dbe3d0 100644 --- a/modules/contact/contact.test +++ b/modules/contact/contact.test @@ -94,6 +94,11 @@ class ContactSitewideTestCase extends DrupalWebTestCase { $this->addCategory($category = $this->randomName(16), implode(',', array($recipients[0], $recipients[1], $recipients[2])), '', FALSE); $this->assertRaw(t('Category %category has been saved.', array('%category' => $category)), t('Category successfully saved.')); + // Try adding a category that already exists. + $this->addCategory($category, '', '', FALSE); + $this->assertNoRaw(t('Category %category has been saved.', array('%category' => $category)), t('Category not saved.')); + $this->assertRaw(t('A contact form with category %category already exists.', array('%category' => $category)), t('Duplicate category error found.')); + // Clear flood table in preparation for flood test and allow other checks to complete. db_delete('flood')->execute(); $num_records_after = db_query("SELECT COUNT(*) FROM {flood}")->fetchField(); |