function constant_contact_form_user_register_alter in Constant Contact 6.3
Same name and namespace in other branches
- 6.2 constant_contact.module \constant_contact_form_user_register_alter()
Alter the user registration form
File
- ./
constant_contact.module, line 241
Code
function constant_contact_form_user_register_alter(&$form, &$form_state) {
$subscribe_method = variable_get('cc_register_page_method', CC_REGISTER_PAGE_METHOD);
$list_format = variable_get('cc_list_selection_format', CC_LIST_SELECTION_FORMAT);
$default_opt_in = variable_get('cc_default_opt_in', CC_DEFAULT_OPT_IN);
$show_format_choice = variable_get('cc_show_format_choice', CC_SHOW_FORMAT_CHOICE);
$default_subscribe_format = variable_get('cc_subscribe_format', CC_SUBSCRIBE_FORMAT);
if ($subscribe_method == 'none') {
return;
}
$cc = constant_contact_create_object();
if (!is_object($cc)) {
return;
}
$lists = array();
$selected_lists = array();
if ($subscribe_method == 'lists') {
$exclude_lists = variable_get('cc_lists', array());
$lists = constant_contact_get_lists($cc);
// select all lists by default, if enabled
if ($lists && $default_opt_in) {
foreach ($lists as $k => $v) {
$selected_lists[$k] = $v['id'];
}
}
$options = array();
foreach ($lists as $list_id => $list_name) {
if (!in_array($list_id, $exclude_lists)) {
$options[$list_id] = $list_name;
}
}
if (count($options) > 0) {
if ($list_format == 'select') {
$field_type = 'select';
}
else {
$field_type = 'checkboxes';
}
$form['account']['cc_newsletter_lists'] = array(
'#type' => $field_type,
'#title' => variable_get('cc_signup_title', CC_SIGNUP_TITLE),
'#description' => variable_get('cc_signup_description', CC_SIGNUP_DESCRIPTION),
'#options' => $options,
'#weight' => 11,
'#default_value' => $selected_lists,
);
if ($list_format == 'select') {
$field_size = $options && count($options) > 25 ? 25 : count($options);
$form['account']['cc_newsletter_lists']['#multiple'] = true;
$form['account']['cc_newsletter_lists']['#size'] = count($options);
}
}
}
else {
$form['account']['cc_newsletter'] = array(
'#type' => 'checkbox',
'#title' => variable_get('cc_signup_title', CC_SIGNUP_TITLE),
'#description' => variable_get('cc_signup_description', CC_SIGNUP_DESCRIPTION),
'#weight' => 10,
'#default_value' => $default_opt_in,
);
}
if ($show_format_choice) {
$form['account']['cc_email_format'] = array(
'#type' => 'radios',
'#title' => t('Email Format'),
'#description' => 'You can receive emails in Text or HTML format',
'#weight' => 12,
'#default_value' => $default_subscribe_format,
'#options' => array(
'Text' => 'Text',
'HTML' => 'HTML',
),
);
}
return $form;
}