CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • CiviCRM Subscribe problem
Pages: [1]

Author Topic: CiviCRM Subscribe problem  (Read 1429 times)

webguy2

  • Guest
CiviCRM Subscribe problem
October 08, 2008, 02:25:15 pm
I finally got this mod working but now it's tuned into a developer issues because it's throwing the same error every time I enter an email,

The function is:
function civicrm_subscribe($email, $params = array(), $groups = array()) {

Under the line below I added some debugging code:
$contact =& crm_get_contact(array('email' => $email));

echo "<pre>contact:";
print_r($contact);
echo "<pre>";exit;

It display onlt the label, "Contact".

If instead I put:
echo "<pre>groups:";
print_r($groups);
echo "<pre>";exit;

it displays:
groups:Array
(
   
  • => 6

)

So, it's not getting/creating the contact using:
crm_get_contact(array('email' => $email))

Any ideas?

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CiviCRM Subscribe problem
October 08, 2008, 04:05:18 pm
Please update your forum profile.

You need to use civicrm_contact_add() for adding new contacts.

Kurund
Found this reply helpful? Support CiviCRM

webguy2

  • Guest
Re: CiviCRM Subscribe problem
October 09, 2008, 05:49:09 am
So the CiviCRM Subscribe, partially supported by CiviActions, is using the wrong code in the module?

Here's the code leading up to that point:
function civicrm_subscribe($email, $params = array(), $groups = array()) {
  if (module_exists('civicrm')) {
    civicrm_initialize(true);

    // if groups specified, then get the default group(s)
    if (count($groups) == 0) {
      $groups = _civicrm_subscribe_get_groups();
    }

    // get (or create) the contact
    $contact =& crm_get_contact(array('email' => $email));

Note that that last line gets or creates a new contact.  Does the civicrm_contact_add() get or create one or do I need to replace that one line with several?  If so, can you point me to the documentation?

Many many thanks for your help!

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CiviCRM Subscribe problem
October 09, 2008, 08:50:06 am
Quote
$contact =& crm_get_contact(array('email' => $email));

This api only retrieves existing contact data. This is deprecated api and you should use:
http://wiki.civicrm.org/confluence/display/CRMDOC/Contact+APIs#ContactAPIs-civicrmcontactget(%26%24params)

Quote
civicrm_contact_add()
http://wiki.civicrm.org/confluence/display/CRMDOC/Contact+APIs#ContactAPIs-civicrmcontactadd(%26%24params)

HTH

Kurund
Found this reply helpful? Support CiviCRM

webguy2

  • Guest
Re: CiviCRM Subscribe problem
October 09, 2008, 12:50:50 pm
So I would do something like:

$params = array( 'email' => $email );
If(&civicrm_contact_get( $params )){
   $contact =&civicrm_contact_get($params)
}else{
    $params = array('email'         => 'dan.conberg@myco.com');
    $contact =&civicrm_contact_add($params);
}

?

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • CiviCRM Subscribe problem

This forum was archived on 2017-11-26.