You are here

function contact_mail_user in Contact 6.2

Form builder; the personal contact form.

See also

contact_mail_user_validate()

contact_mail_user_submit()

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

File

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

Code

function contact_mail_user($form_state, stdClass $recipient) {
  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') && !user_access('administer users')) {
    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();
  }
  drupal_set_title(t('Contact @username', array(
    '@username' => $recipient->name,
  )));
  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['recipient'] = array(
    '#type' => 'value',
    '#value' => $recipient,
  );
  $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['to'] = array(
    '#type' => 'item',
    '#title' => t('To'),
    '#value' => theme('username', $recipient),
  );
  $form['subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#maxlength' => 50,
    '#required' => TRUE,
  );
  $form['message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message'),
    '#rows' => 15,
    '#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;
}