contact_mail_page

  1. drupal
    1. 4.7
    2. 5 contact.module
    3. 6 contact.pages.inc
Versions
4.7 – 6 contact_mail_page()

Site-wide contact page

Code

modules/contact.module, line 408

<?php
function contact_mail_page() {
  global $user;

  if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
    $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3)));
  }
  else {
    if ($user->uid) {
      $edit['name'] = $user->name;
      $edit['mail'] = $user->mail;
    }

    $result = db_query('SELECT cid, category, selected FROM {contact} ORDER BY weight, category');
    while ($category = db_fetch_object($result)) {
      $categories[$category->cid] = $category->category;
      if ($category->selected) {
        $default_category = $category->cid;
      }
    }

    if (count($categories) > 0) {
      $form['#token'] = $user->name . $user->mail;
      $form['contact_information'] = array('#value' => filter_xss_admin(variable_get('contact_form_information', t('You can leave us a message using the contact form below.'))));
      $form['name'] = array(
        '#type' => 'textfield', 
        '#title' => t('Your name'), 
        '#maxlength' => 255, 
        '#default_value' => $edit['name'], 
        '#required' => TRUE,
      );
      $form['mail'] = array(
        '#type' => 'textfield', 
        '#title' => t('Your e-mail address'), 
        '#maxlength' => 255, 
        '#default_value' => $edit['mail'], 
        '#required' => TRUE,
      );
      $form['subject'] = array(
        '#type' => 'textfield', 
        '#title' => t('Subject'), 
        '#maxlength' => 255, 
        '#required' => TRUE,
      );
      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)) {
          $categories = array(t('--')) + $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,
      );
      if ($user->uid) {
        $form['copy'] = array(
          '#type' => 'checkbox', 
          '#title' => t('Send me a copy.'),
        );
      }
      $form['submit'] = array(
        '#type' => 'submit', 
        '#value' => t('Send e-mail'),
      );
      $output = drupal_get_form('contact_mail_page', $form);
    }
    else {
      $output = t('The contact form has not been configured.');
    }
  }

  return $output;
}
?>