function contact_personal_form

Page callback: Form constructor for the personal contact form.

Parameters

$recipient: The account for which a personal contact form should be generated.

Throws

\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException

See also

contact_menu()

contact_personal_form_submit()

Related topics

1 string reference to 'contact_personal_form'
contact_menu in drupal/core/modules/contact/contact.module
Implements hook_menu().

File

drupal/core/modules/contact/contact.pages.inc, line 191
Page callbacks for the Contact module.

Code

function contact_personal_form($form, &$form_state, $recipient) {
  global $user;

  // Check if flood control has been activated for sending e-mails.
  $config = config('contact.settings');
  $limit = $config
    ->get('flood.limit');
  $interval = $config
    ->get('flood.interval');
  if (!drupal_container()
    ->get('flood')
    ->isAllowed('contact', $limit, $interval) && !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($interval),
    )), 'error');
    throw new AccessDeniedHttpException();
  }
  drupal_set_title(t('Contact @username', array(
    '@username' => user_format_name($recipient),
  )), PASS_THROUGH);
  if (!$user->uid) {
    $form['#attached']['library'][] = array(
      'system',
      'jquery.cookie',
    );
    $form['#attributes']['class'][] = 'user-info-from-cookie';
  }
  $form['#attributes']['class'][] = 'contact-form';
  $form['recipient'] = array(
    '#type' => 'value',
    '#value' => $recipient,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Your name'),
    '#maxlength' => 255,
    '#default_value' => $user->uid ? user_format_name($user) : '',
    '#required' => TRUE,
  );
  $form['mail'] = array(
    '#type' => 'email',
    '#title' => t('Your e-mail address'),
    '#default_value' => $user->uid ? $user->mail : '',
    '#required' => TRUE,
  );

  // Do not allow authenticated users to alter the name or e-mail values to
  // prevent the impersonation of other users.
  if ($user->uid) {

    // Hide the original name and e-mail address fields and display read-only
    // versions in their place.
    $form['name']['#access'] = $form['mail']['#access'] = FALSE;
    $form['name_display'] = array(
      '#type' => 'item',
      '#title' => t('Your name'),
      '#markup' => check_plain($form['name']['#default_value']),
    );
    $form['mail_display'] = array(
      '#type' => 'item',
      '#title' => t('Your e-mail address'),
      '#markup' => check_plain($form['mail']['#default_value']),
    );
  }
  $form['to'] = array(
    '#type' => 'item',
    '#title' => t('To'),
    '#markup' => theme('username', array(
      'account' => $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,
  );

  // 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' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send message'),
  );
  return $form;
}