You are here

function mailchimp_subscribe_auth_form in Mailchimp 7

Same name and namespace in other branches
  1. 6.2 mailchimp.module \mailchimp_subscribe_auth_form()

Add mailchimp form fields to account and registration forms

1 call to mailchimp_subscribe_auth_form()
mailchimp_form_user_register_form_alter in ./mailchimp.module
Implements hook_form_FORM_ID_alter(). Add newsletter fields to registration form.
2 string references to 'mailchimp_subscribe_auth_form'
mailchimp_menu in ./mailchimp.module
Implements hook_menu().
mailchimp_subscribe_page in ./mailchimp.module
Return all available MC lists a given user can subscribe to

File

./mailchimp.module, line 166
Mailchimp module.

Code

function mailchimp_subscribe_auth_form($form, $form_state, $account, $standalone = TRUE, $list = NULL) {
  $form = array();

  // get all available non-required lists
  $lists = !empty($list) ? array(
    $list,
  ) : _mailchimp_get_available_lists($account, TRUE);
  if (count($lists) == 0) {
    $form['value'] = array(
      '#markup' => t('There are no available newsletters subscriptions.'),
      '#prefix' => '<div>',
      '#suffix' => '</div>',
    );
  }
  else {
    if ($q = _mailchimp_get_api_object()) {
      if ($account->uid > 0) {
        $form['uid'] = array(
          '#type' => 'hidden',
          '#value' => $account->uid,
        );
      }
      else {

        // user registration or admin creating new user
        $account->roles = array(
          2 => 'authenticated',
        );
      }
      foreach ($lists as $list) {
        mailchimp_auth_newsletter_form($form, $list, $account, $q);
      }
      if ($standalone) {
        $form['submit'] = array(
          '#type' => 'submit',
          '#value' => t('save settings'),
          '#weight' => 100,
        );
      }
    }
  }
  return $form;
}