Skip to content
Snippets Groups Projects
Commit 8151b56c authored by Angie Byron's avatar Angie Byron
Browse files

#246880 by mr.baileys: Fixed Error when adding duplicate category to contact...

#246880 by mr.baileys: Fixed Error when adding duplicate category to contact form module (with tests).
parent db7f5e4c
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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)) {
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment