You are here

function print_mail_form in Printer, email and PDF versions 5.3

Same name and namespace in other branches
  1. 5.4 print_mail/print_mail.inc \print_mail_form()
  2. 6 print_mail/print_mail.inc \print_mail_form()
  3. 7.2 print_mail/print_mail.inc \print_mail_form()
  4. 7 print_mail/print_mail.inc \print_mail_form()
  5. 5.x print_mail/print_mail.inc \print_mail_form()

Menu callback for the send by e-mail form.

1 string reference to 'print_mail_form'
print_mail_menu in print_mail/print_mail.module
Implementation of hook_menu().

File

print_mail/print_mail.inc, line 18

Code

function print_mail_form($form_state) {
  global $user;
  $print_mail_hourly_threshold = variable_get('print_mail_hourly_threshold', PRINT_MAIL_HOURLY_THRESHOLD);
  if (!flood_is_allowed('print_mail', $print_mail_hourly_threshold)) {
    $form['flood'] = array(
      '#type' => 'markup',
      '#value' => '<p>' . t('You cannot send more than %number messages per hour. Please try again later.', array(
        '%number' => $print_mail_hourly_threshold,
      )) . '</p>',
    );
    return $form;
  }
  $print_mail_teaser_default = variable_get('print_mail_teaser_default', PRINT_MAIL_TEASER_DEFAULT_DEFAULT);
  $print_mail_teaser_choice = variable_get('print_mail_teaser_choice', PRINT_MAIL_TEASER_CHOICE_DEFAULT);
  $form = array();

  // Remove the printmail/ prefix
  $path = explode('/', $_GET['q']);
  unset($path[0]);
  $path = implode('/', $path);
  if (is_numeric($path)) {
    $path = 'node/' . $path;
  }
  $cid = isset($_GET['comment']) ? (int) $_GET['comment'] : NULL;
  $form['path'] = array(
    '#type' => 'value',
    '#value' => $path,
  );
  $form['cid'] = array(
    '#type' => 'value',
    '#value' => $cid,
  );
  $form['fld_from_addr'] = array(
    '#type' => 'textfield',
    '#title' => t('Your e-mail'),
    '#size' => 62,
  );
  $form['fld_from_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Your name'),
    '#size' => 62,
  );
  $form['txt_to_addrs'] = array(
    '#type' => 'textarea',
    '#title' => t('Send to'),
    '#rows' => 3,
    '#resizable' => FALSE,
    '#description' => t('Enter multiple addresses separated by commas and/or different lines.'),
  );
  $form['fld_subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#size' => 62,
  );
  $form['txt_message'] = array(
    '#type' => 'textarea',
    '#title' => t('Your message'),
    '#rows' => 6,
  );
  if ($print_mail_teaser_choice) {
    $form['chk_teaser'] = array(
      '#type' => 'checkbox',
      '#title' => t('Send only the teaser'),
      '#default_value' => $print_mail_teaser_default,
    );
  }
  else {
    $form['chk_teaser'] = array(
      '#type' => 'value',
      '#value' => $print_mail_teaser_default,
    );
  }
  $form['btn_submit'] = array(
    '#name' => 'submit',
    '#type' => 'submit',
    '#value' => t('Send e-mail'),
  );
  $form['btn_clear'] = array(
    '#name' => 'clear',
    '#type' => 'button',
    '#value' => t('Clear form'),
    '#attributes' => array(
      'onclick' => 'this.form.reset(); return false;',
    ),
  );
  $form['btn_cancel'] = array(
    '#name' => 'cancel',
    '#type' => 'submit',
    '#value' => t('Cancel'),
  );
  if ($user->uid != 0) {
    $user_name = $user->name;
    $form['fld_from_addr']['#default_value'] = $user->mail;
    $form['fld_from_addr']['#disabled'] = TRUE;
    $form['fld_from_addr']['#value'] = $user->mail;
    $form['fld_from_name']['#default_value'] = $user->name;
  }
  else {
    $user_name = t('Someone');
  }
  $site_name = variable_get('site_name', t('an interesting site'));
  $form['fld_subject']['#default_value'] = t('!user has sent you a message from !site', array(
    '!user' => $user_name,
    '!site' => $site_name,
  ));
  return $form;
}