1 contact.pages.inc contact_personal_form($form, &$form_state, $recipient)

Form constructor for the personal contact form.

See also

contact_menu()

contact_personal_form_validate()

contact_personal_form_submit()

Related topics

File

core/modules/contact/contact.pages.inc, line 192
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 emails.
  $config = config('contact.settings');
  $limit = $config->get('contact_threshold_limit');
  $window = $config->get('contact_threshold_window');
  if (!flood_is_allowed('contact', $limit, $window) && !user_access('administer contact forms') && !user_access('administer users')) {
    backdrop_set_message(t("You cannot send more than %limit messages in @interval. Try again later.", array('%limit' => $limit, '@interval' => format_interval($window))), 'error');
    return array();
  }

  backdrop_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 email address'),
    '#default_value' => $user->uid ? $user->mail : '',
    '#required' => TRUE,
  );
  $phone = $config->get('phone');
  if (!empty($phone)) {
    $form['phone'] = array(
      '#type' => 'tel',
      '#title' => t('Your phone number'),
      '#required' => $phone == 'required',
    );
  }
  $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,
  );
  // 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 && contact_show_personal_copy_checkbox(),
  );
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send message'),
  );
  return $form;
}