Fix for Fix for CiviCRM: Creating Newsletter Subscriber and Adding to Group

  1. <?php
  2. function bronto_add_civicrm($form_values, $params = array()){
  3.  if (module_exists('civicrm')) {
  4.     civicrm_initialize(true);
  5.         require_once 'api/crm.php';
  6.        
  7.     // get (or create) the contact
  8.     $contact =& crm_get_contact(array('email' => $email));
  9.     if (!$contact || !isset($contact->id)) {
  10.        
  11.          $params = array('first_name'    => $form_values['first_name'],
  12.                      'last_name'     => $form_values['last_name'],
  13.                      'email'         => $form_values['email'],
  14.                      'state_province'=> $form_values['state'],
  15.                      );
  16.        
  17.   $contact =& crm_create_contact($params, 'Individual');
  18.  
  19.   //add contact to group
  20.   $contacts = array($contact);
  21.  
  22.   // Load civicrm group from group id.
  23.   $group_id = array('id' => '1');  // ID for newsletter group.
  24.   $group = crm_get_groups($group_id);
  25.   $group = $group[0];
  26.  
  27.   // Add user to group.
  28.   crm_add_group_contacts($group, $contacts, 'Added', $method = 'Bronto');
  29.                 }
  30.         }
  31. }
  32.  
  33. ?>

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.