summaryrefslogtreecommitdiff
path: root/modules/contact
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-04-21 09:27:52 +0000
committerDries Buytaert <dries@buytaert.net>2009-04-21 09:27:52 +0000
commita7c324f42c942eb7728639ec1a58e78134d46eb1 (patch)
tree2ae52a8df9f19b8484df2f6bbcad577656924f50 /modules/contact
parent1280c324fa10f3a1eb4f2f67584e8fa77784f7b8 (diff)
downloadbrdo-a7c324f42c942eb7728639ec1a58e78134d46eb1.tar.gz
brdo-a7c324f42c942eb7728639ec1a58e78134d46eb1.tar.bz2
- Patch #282858 by Dave Reid, Ian Ward: nicer message for the contact form when it has not yet been configured.
Diffstat (limited to 'modules/contact')
-rw-r--r--modules/contact/contact.pages.inc138
-rw-r--r--modules/contact/contact.test7
2 files changed, 70 insertions, 75 deletions
diff --git a/modules/contact/contact.pages.inc b/modules/contact/contact.pages.inc
index 00ad4cab8..c1fe3acca 100644
--- a/modules/contact/contact.pages.inc
+++ b/modules/contact/contact.pages.inc
@@ -11,11 +11,17 @@
* Site-wide contact page.
*/
function contact_site_page() {
- global $user;
-
if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3)) && !user_access('administer site-wide contact form')) {
$output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3)));
}
+ elseif (!db_query("SELECT COUNT(cid) FROM {contact}")->fetchField()) {
+ if (user_access('administer site-wide contact form')) {
+ $output = t('The contact form has not been configured. <a href="@add">Add one or more categories</a> to the form.', array('@add' => url('admin/build/contact/add')));
+ }
+ else {
+ return drupal_not_found();
+ }
+ }
else {
$output = drupal_get_form('contact_mail_page');
}
@@ -26,83 +32,69 @@ function contact_site_page() {
function contact_mail_page() {
global $user;
- $form = $categories = array();
-
- $result = db_select('contact')
- ->fields('contact', array('cid', 'category', 'selected'))
- ->orderby('weight')
- ->orderby('category')
- ->execute();
+ $categories = db_query("SELECT cid, category FROM {contact} ORDER BY weight, category")->fetchAllKeyed();
+ $default_category = (int) db_query("SELECT cid FROM {contact} WHERE selected = 1")->fetchField();
- foreach ($result as $record) {
- $categories[$record->cid] = $record->category;
- if ($record->selected) {
- $default_category = $record->cid;
- }
- }
-
- if (count($categories) > 0) {
- $form['#token'] = $user->uid ? $user->name . $user->mail : '';
- $form['contact_information'] = array('#markup' => filter_xss_admin(variable_get('contact_form_information', t('You can leave a message using the contact form below.'))));
- $form['name'] = array('#type' => 'textfield',
- '#title' => t('Your name'),
- '#maxlength' => 255,
- '#default_value' => $user->uid ? $user->name : '',
- '#required' => TRUE,
- );
- $form['mail'] = array('#type' => 'textfield',
- '#title' => t('Your e-mail address'),
- '#maxlength' => 255,
- '#default_value' => $user->uid ? $user->mail : '',
- '#required' => TRUE,
- );
- $form['subject'] = array('#type' => 'textfield',
- '#title' => t('Subject'),
- '#maxlength' => 255,
- '#required' => TRUE,
- );
+ // If there is more than one category available and no default category has been selected,
+ // prepend a default placeholder value.
+ if (!$default_category) {
if (count($categories) > 1) {
- // If there is more than one category available and no default category has been selected,
- // prepend a default placeholder value.
- if (!isset($default_category)) {
- $default_category = t('- Please choose -');
- $categories = array($default_category) + $categories;
- }
- $form['cid'] = array('#type' => 'select',
- '#title' => t('Category'),
- '#default_value' => $default_category,
- '#options' => $categories,
- '#required' => TRUE,
- );
- }
- else {
- // If there is only one category, store its cid.
- $category_keys = array_keys($categories);
- $form['cid'] = array('#type' => 'value',
- '#value' => array_shift($category_keys),
- );
- }
- $form['message'] = array('#type' => 'textarea',
- '#title' => t('Message'),
- '#required' => TRUE,
- );
- // We do not allow anonymous users to send themselves a copy
- // because it can be abused to spam people.
- if ($user->uid) {
- $form['copy'] = array('#type' => 'checkbox',
- '#title' => t('Send yourself a copy.'),
- );
+ $categories = array(0 => t('- Please choose -')) + $categories;
}
else {
- $form['copy'] = array('#type' => 'value', '#value' => FALSE);
+ $default_category = key($categories);
}
- $form['submit'] = array('#type' => 'submit',
- '#value' => t('Send e-mail'),
- );
- }
- else {
- drupal_set_message(t('The contact form has not been configured. <a href="@add">Add one or more categories</a> to the form.', array('@add' => url('admin/build/contact/add'))), 'error');
}
+
+ $form['#token'] = $user->uid ? $user->name . $user->mail : '';
+ $form['contact_information'] = array(
+ '#markup' => filter_xss_admin(variable_get('contact_form_information', t('You can leave a message using the contact form below.'))),
+ );
+ $form['name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Your name'),
+ '#maxlength' => 255,
+ '#default_value' => $user->uid ? $user->name : '',
+ '#required' => TRUE,
+ );
+ $form['mail'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Your e-mail address'),
+ '#maxlength' => 255,
+ '#default_value' => $user->uid ? $user->mail : '',
+ '#required' => TRUE,
+ );
+ $form['subject'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Subject'),
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ );
+ $form['cid'] = array(
+ '#type' => 'select',
+ '#title' => t('Category'),
+ '#default_value' => $default_category,
+ '#options' => $categories,
+ '#required' => TRUE,
+ '#access' => count($categories) > 1,
+ );
+ $form['message'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Message'),
+ '#required' => TRUE,
+ );
+ // We do not allow anonymous users to send themselves a copy
+ // because it can be abused to spam people.
+ $form['copy'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Send yourself a copy.'),
+ '#access' => $user->uid,
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Send e-mail'),
+ );
+
return $form;
}
diff --git a/modules/contact/contact.test b/modules/contact/contact.test
index ddc67036f..692b3c752 100644
--- a/modules/contact/contact.test
+++ b/modules/contact/contact.test
@@ -22,7 +22,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
*/
function testSiteWideContact() {
// Create and login administrative user.
- $admin_user = $this->drupalCreateUser(array('administer site-wide contact form', 'administer permissions'));
+ $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer site-wide contact form', 'administer permissions'));
$this->drupalLogin($admin_user);
// Set settings.
@@ -41,8 +41,11 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
$this->setPermission('anonymous user', array('access site-wide contact form' => TRUE));
$this->drupalLogout();
$this->drupalGet('contact');
- $this->assertText(t('The contact form has not been configured.'), t('Contact form will not work without categories configured.'));
+ $this->assertResponse(404);
$this->drupalLogin($admin_user);
+ $this->drupalGet('contact');
+ $this->assertResponse(200);
+ $this->assertText(t('The contact form has not been configured.'));
// Add categories.
// Test invalid recipients.