You are here

function contact_mail_page in Contact 6.2

Form builder; the site-wide contact form.

See also

contact_mail_page_validate()

contact_mail_page_submit()

1 string reference to 'contact_mail_page'
contact_menu in ./contact.module
Implements hook_menu().

File

./contact.pages.inc, line 14
User page callbacks for the contact module.

Code

function contact_mail_page($form_state) {
  global $user;

  // Check if flood control has been activated for sending e-mails.
  $limit = variable_get('contact_threshold_limit', 5);
  $window = variable_get('contact_threshold_window', 3600);
  if (!flood_is_allowed('contact', $limit) && !user_access('administer contact forms')) {
    drupal_set_message(t("You cannot send more than %limit messages in @interval. Try again later.", array(
      '%limit' => $limit,
      '@interval' => format_interval($window),
    )), 'error');
    return drupal_access_denied();

    //drupal_exit();
  }

  // Get an array of the categories and the current default category.
  $categories = array();
  $default_category = 0;
  $query = db_query('SELECT cid, category, selected FROM {contact} ORDER BY weight, category');
  while ($category = db_fetch_object($query)) {
    $categories[$category->cid] = $category->category;
    if ($category->selected) {
      $default_category = $category->cid;
    }
  }

  // If there are no categories, do not display the form.
  if (!$categories) {
    if (user_access('administer contact forms')) {
      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');
    }
    else {
      return drupal_not_found();

      //drupal_exit();
    }
  }

  // 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) {
      $categories = array(
        0 => t('- Please choose -'),
      ) + $categories;
    }
    else {
      $default_category = key($categories);
    }
  }
  if (!$user->uid) {
    drupal_add_js(drupal_get_path('module', 'contact') . '/jquery.cookie.js');
    drupal_add_js(drupal_get_path('module', 'contact') . '/contact.js');
    $form['#attributes']['class'] = 'user-info-from-cookie';
  }
  $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['actions'] = array(

  //  '#type' => 'container',
  //  '#attributes' => array('class' => array('form-actions')),

  //);
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send message'),
  );
  return $form;
}