function mailchimp_form_alter in Mailchimp 5
Same name and namespace in other branches
- 5.2 mailchimp.module \mailchimp_form_alter()
Implementation of hook_form_alter(). Add subscription form to registration page
File
- ./
mailchimp.module, line 118
Code
function mailchimp_form_alter($form_id, &$form) {
if ($form_id == 'user_register' && variable_get('mailchimp_user_register', true)) {
$account = new stdClass();
$account->roles = array(
2 => "authenticated user",
);
$lists = _mailchimp_get_available_lists($account, $q);
if (!empty($lists)) {
foreach ($lists as $list) {
if (variable_get('mailchimp_list_' . $list['id'] . '_listtype', '') !== 'required') {
$list_form['chimpmail_list_' . $list['id']] = array(
'#type' => 'checkbox',
'#title' => $list["name"],
'#default_value' => variable_get('mailchimp_list_' . $list['id'] . '_listtype', '') == 'optout' ? true : false,
'#description' => variable_get('mailchimp_list_' . $list['id'] . '_description', ''),
);
}
}
if ($list_form) {
$form['chimpmail_lists'] = array(
'#type' => 'fieldset',
'#title' => t('Newsletter subscriptions'),
'#weight' => 5,
'#collapsible' => TRUE,
);
$form['chimpmail_lists'] = array_merge($form['chimpmail_lists'], $list_form);
}
}
}
}