function simplenews_subscriptions_page_form in Simplenews 7.2
Same name and namespace in other branches
- 6.2 includes/simplenews.subscription.inc \simplenews_subscriptions_page_form()
- 7 includes/simplenews.subscription.inc \simplenews_subscriptions_page_form()
FAPI PAGE subscription form.
See also
simplenews_subscriptions_page_form_validate()
simplenews_subscriptions_page_form_submit()
1 string reference to 'simplenews_subscriptions_page_form'
- simplenews_menu in ./
simplenews.module - Implements hook_menu().
File
- includes/
simplenews.subscription.inc, line 210 - (Un)subscription and (un)subscription confirmation
Code
function simplenews_subscriptions_page_form($form, &$form_state, $snid = NULL, $timestamp = NULL, $hash = NULL) {
global $user;
$subscriber = $mail = FALSE;
if (!empty($user->mail)) {
$subscriber = simplenews_subscriber_load_by_mail($user->mail);
$mail = $user->mail;
}
elseif ($snid && $timestamp && $hash) {
$subscriber = simplenews_subscriber_load($snid);
if ($subscriber && $hash == simplenews_generate_hash($subscriber->mail, 'manage', $timestamp)) {
$mail = $subscriber->mail;
}
else {
drupal_not_found();
return array();
}
}
$form = array();
$options = array();
$default_value = array();
// Get newsletters for subscription form checkboxes.
// Newsletters with opt-in/out method 'hidden' will not be listed.
foreach (simplenews_newsletter_get_visible() as $newsletter) {
$options[$newsletter->newsletter_id] = check_plain($newsletter->name);
$default_value[$newsletter->newsletter_id] = FALSE;
}
if ($subscriber) {
// If there is an existing subscriber object, use the existing settings.
$default_value = array_merge($default_value, $subscriber->newsletter_ids);
}
$form['subscriptions'] = array(
'#type' => 'fieldset',
);
$form['subscriptions']['newsletters'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $default_value,
);
// If we have a mail address, which is either from a logged in user or a
// subscriber identified through the hash code, display the mail address
// instead of a textfield. Anonymous uses will still have to confirm any
// changes.
if ($mail) {
$form['subscriptions']['#title'] = t('Subscriptions for %mail', array(
'%mail' => $mail,
));
$form['subscriptions']['#description'] = t('Check the newsletters you want to subscribe to. Uncheck the ones you want to unsubscribe from.');
$form['subscriptions']['mail'] = array(
'#type' => 'value',
'#value' => $mail,
);
$form['update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#weight' => 20,
);
}
else {
$form['subscriptions']['#title'] = t('Manage your newsletter subscriptions');
$form['subscriptions']['#description'] = t('Select the newsletter(s) to which you want to subscribe or unsubscribe.');
$form['subscriptions']['mail'] = array(
'#type' => 'textfield',
'#title' => t('E-mail'),
'#size' => 20,
'#maxlength' => 128,
'#weight' => 10,
'#required' => TRUE,
);
$form['subscribe'] = array(
'#type' => 'submit',
'#value' => t('Subscribe'),
'#weight' => 20,
);
$form['unsubscribe'] = array(
'#type' => 'submit',
'#value' => t('Unsubscribe'),
'#weight' => 30,
);
}
$form['#validate'][] = 'simplenews_subscriptions_page_form_validate';
$form['#submit'][] = 'simplenews_subscriptions_page_form_submit';
return $form;
}