You are here

function mailing_list_subscription_form in Mailing List 7

Same name and namespace in other branches
  1. 6 mailing_list.module \mailing_list_subscription_form()

Display a form letting a user subscribe to a mailing list.

2 string references to 'mailing_list_subscription_form'
mailing_list_forms in ./mailing_list.module
Implement hook_forms().
mailing_list_menu in ./mailing_list.module
Implement hook_menu().

File

./mailing_list.module, line 389
Minimalistic mailing list module.

Code

function mailing_list_subscription_form($form, &$form_state, $list, $is_callback = FALSE, $email = NULL) {
  $admin = FALSE;
  if (user_access('administer mailing lists')) {
    $admin = TRUE;
    $is_edit = !empty($email);
    if ($is_callback) {
      if ($is_edit) {
        $title = t("Editing @email on @list_name", array(
          '@list_name' => $list->name,
          '@email' => $email->mail,
        ));
      }
      else {
        $title = t("Adding email to @list_name", array(
          '@list_name' => $list->name,
        ));
      }
      drupal_set_title($title);
    }
  }
  else {

    // Ensure that no one else can edit an entry.
    $email = NULL;
  }
  $form = array();
  $form['mlid'] = array(
    '#type' => 'hidden',
    '#default_value' => $list->mlid,
  );
  $form['ml_name'] = array(
    '#type' => 'hidden',
    '#value' => $list->name,
  );
  if (variable_get('mailing_list_show_name_' . $list->mlid, 1)) {
    $form['name'] = array(
      '#title' => t('Name'),
      '#type' => 'textfield',
      '#size' => 20,
      '#required' => TRUE,
    );
  }
  else {
    $form['name'] = array(
      '#type' => 'hidden',
      '#value' => '',
    );
  }
  $form['mail'] = array(
    '#title' => t('E-mail'),
    '#type' => 'textfield',
    '#size' => 20,
    '#required' => TRUE,
  );
  $form['submit'] = array(
    '#value' => t('Subscribe'),
    '#type' => 'submit',
    '#submit' => array(
      'mailing_list_subscription_form_submit',
    ),
  );
  if ($admin && $email) {
    $form['name']['#default_value'] = $email->name;
    $form['mail']['#default_value'] = $email->mail;
    $form['eid'] = array(
      '#type' => 'value',
      '#default_value' => $email->eid,
    );
  }
  $form['#validate'] = array(
    'mailing_list_subscription_form_validate',
  );
  return $form;
}