function contact_personal_form

Form constructor for the personal contact form.

Path: user/%user/contact

See also

contact_menu()

contact_personal_form_validate()

contact_personal_form_submit()

Related topics

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

File

modules/contact/contact.pages.inc, line 183

Code

function contact_personal_form($form, &$form_state, $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, $window) && !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');
        drupal_access_denied();
        drupal_exit();
    }
    drupal_set_title(t('Contact @username', array(
        '@username' => format_username($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 ? format_username($user) : '',
        '#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'),
        '#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,
    );
    $form['actions'] = array(
        '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Send message'),
    );
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.