You are here

function constant_contact_block_form_submit in Constant Contact 5

Same name and namespace in other branches
  1. 6 constant_contact.module \constant_contact_block_form_submit()

Implementation of hook_form_submit() process the join mailing list block

File

./constant_contact.module, line 274

Code

function constant_contact_block_form_submit($form_id, $values) {
  global $user;
  $data = array();
  if ($user->uid) {
    $email = $user->mail;
    $data['Custom_field_1'] = $user->name;
    $data['Custom_field_2'] = $user->uid;
    $data['Custom_field_3'] = date('r');
  }
  else {
    $email = $values['email'];
  }
  require_once 'ConstantContact.php';
  $constant_contact = new ConstantContact();
  $constant_contact
    ->setUsername(variable_get('constant_contact_username', ''));
  $constant_contact
    ->setPassword(variable_get('constant_contact_password', ''));
  $constant_contact
    ->setCategory($values['list']);
  if ($constant_contact
    ->add($email, $data)) {
    $type = 'status';
    $message = 'You have been added to our list.';
    if (variable_get('constant_contact_sendemail', TRUE)) {
      constant_contact_confirmation_email($email, $values['list']);
    }
    constant_contact_save_user($user, $values['list']);
  }
  else {
    $type = 'error';
    $message = 'There was a problem adding you to the list';
  }
  drupal_set_message(t($message), $type);
}