function simplenews_subscriptions_multi_block_form in Simplenews 7.2
Same name and namespace in other branches
- 6.2 includes/simplenews.subscription.inc \simplenews_subscriptions_multi_block_form()
- 7 includes/simplenews.subscription.inc \simplenews_subscriptions_multi_block_form()
FAPI MULTI BLOCK subscription form.
Menu callback: Generates the subscription form for users for the multisignup block.
See also
simplenews_subscriptions_multi_block_form_validate()
simplenews_subscriptions_multi_block_form_submit()
1 string reference to 'simplenews_subscriptions_multi_block_form'
- template_preprocess_simplenews_multi_block in ./
simplenews.module - Process variables for the multi subscription block.
File
- includes/
simplenews.subscription.inc, line 381 - (Un)subscription and (un)subscription confirmation
Code
function simplenews_subscriptions_multi_block_form($form, &$form_state) {
global $user;
$subscriber = !empty($user->mail) ? simplenews_subscriber_load_by_mail($user->mail) : FALSE;
// If someone not authorized to edit their subscription, return empty form.
if (!user_access('subscribe to newsletters')) {
return;
}
$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['newsletters'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $default_value,
);
// If current user is logged in, just display email.
// Anonymous users see an email box and will receive confirmations
if (user_is_logged_in()) {
// @todo why not simply Manage your subscriptions?
$form['mail'] = array(
'#type' => 'value',
'#value' => $user->mail,
);
$form['update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#weight' => 20,
);
}
else {
$form['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;
}