Default Subscribe Checkbox for Registration

g10tto - October 8, 2009 - 15:48
Project:MailChimp
Version:6.x-2.0-beta5
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I'm looking at these lines, not being much of a good coder, and I'm just wondering how I could make the checkbox for subscribing to a newsletter on the registration page checked by default:

/**
* Implementation of hook_form_alter() .
* Add subscription form to registration page
*/
function mailchimp_form_user_register_alter(&$form, &$form_state) {
  if (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);

      }
    }
  }
}

#1

LouBabe - October 8, 2009 - 16:11
Status:active» fixed

You just mark it as optout rather than optin on the settings page for that newsletter.

#2

g10tto - October 8, 2009 - 17:25

Never noticed that section.

Thank you!

#3

System Message - October 22, 2009 - 17:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.