Fix for CiviCRM: Creating Newsletter Subscriber and Adding to Group

  1. <?php
  2. //the function below simultaneousy adds new contacts to CiviCRM
  3. function bronto_add_civicrm($form_values, $params = array(), $groups = array()) {
  4.   if (module_exists('civicrm')) {
  5.     civicrm_initialize(true);
  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);
  18.  
  19.         // Add user to group.
  20.         $contacts = array($contact);
  21.        
  22.         //get group 1, newsletter subscribers
  23.         $group = crm_get_groups(array('id' => '1'));
  24.         crm_add_group_contacts($group, $contacts, 'Added', 'Bronto');
  25.  
  26.                 }
  27.         }
  28. }    
  29.  
  30. ?>

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.