function mailchimp_subscribe_form in Mailchimp 6
Same name and namespace in other branches
- 5.2 mailchimp.module \mailchimp_subscribe_form()
- 5 mailchimp.module \mailchimp_subscribe_form()
1 string reference to 'mailchimp_subscribe_form'
- mailchimp_menu in ./
mailchimp.module - Implementation of hook_menu.
File
- ./
mailchimp.module, line 435 - Mailchimp module.
Code
function mailchimp_subscribe_form() {
global $user;
if ($user->uid) {
drupal_set_message(t('You can manage your newsletter subscriptions from your ' . l('user account page', 'user') . '.'));
}
else {
if ($q = _mailchimp_get_api_object()) {
$lists = _mailchimp_get_available_lists($user, $q);
if (count($lists) > 0) {
foreach ($lists as $list) {
$form['list_' . $list['id']] = array(
'#type' => 'fieldset',
'#title' => $list['name'],
'#collapsible' => TRUE,
'#tree' => TRUE,
);
$checked = variable_get('mailchimp_list_' . $list['id'] . '_listtype', 'optin') == "optout" ? 1 : 0;
$form['list_' . $list['id']][$list['id']] = array(
'#type' => 'checkbox',
'#title' => t('Subscribe to the @newsletter newsletter', array(
'@newsletter' => $list['name'],
)),
'#default_value' => $checked,
'#description' => variable_get('mailchimp_list_' . $list['id'] . '_description', ''),
);
foreach ((array) $q
->listMergeVars($list['id']) as $mergevar) {
$form['list_' . $list['id']][$mergevar['tag']] = array(
'#type' => 'textfield',
'#title' => $mergevar['name'],
);
}
if ($intgroup = $q
->listInterestGroups($list['id'])) {
$form['list_' . $list['id']][$intgroup['name']] = array(
'#type' => 'fieldset',
'#title' => $intgroup['name'],
);
foreach ((array) $intgroup['groups'] as $group) {
$form['list_' . $list['id']][$intgroup['name']][$group] = array(
'#type' => $intgroup['form_field'],
'#title' => $group,
);
}
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Sign Up!'),
);
}
}
return $form;
}
}