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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Sending Contact Information on Create/Update
Pages: [1]

Author Topic: Sending Contact Information on Create/Update  (Read 533 times)

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Sending Contact Information on Create/Update
July 30, 2014, 10:43:22 pm
I am trying to write some code that when a contact is created/updated it sends first, last, phone, and groups to an API with a new texting service Telerivet.

How would I go about this?  Here is my first chunk of code... How do I get the variables after the form is saved?  PS:  I will only be adding/updating contact information from the backend.  Am I using the right hook?
Code: [Select]
function joomla_civicrm_processProfile($name) {
  if ($objectName == "Individual" && $op == "edit") {
  //Get Variables Civicrm
    $firstName = $objectRef->first_name;
        $lastName = $objectRef->last_name;
 
   // Telerivet code
    $contact = $project->getOrCreateContact(array(
    'name' => '$displayName',
    'phone_number' => "$phone_numberic",
    'vars' => array('first' => '$firstName', 'last' => '$lastName')
));
  }
}
« Last Edit: July 30, 2014, 10:52:58 pm by zesgar »

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: Sending Contact Information on Create/Update
July 31, 2014, 11:54:17 am
I see a few issues here, but some of them may be because I'm not Joomla-savvy.  I don't see a processProfile hook in the CiviCRM hook reference though.

A question though - are you only trying to reach folks who gave through a certain form? Or any time a contact is entered?  If the latter, I'd use civicrm_post.  If through a certain form, use the postProcess hook.

It also looks like you only have one parameter on your hook ($name), but make sure you include all the parameters for the appropriate hook.  For a postProcess hook, the form values are in the $form array.  For a contact, it's in the $objectRef properties.
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Re: Sending Contact Information on Create/Update
July 31, 2014, 03:51:03 pm
Thanks so much for you help.   I am wanting it to limit it to just when a contact is entered or updated from the backend Add New Individual or on editing an individual

Here is some updated Code I am using.  I just don't know how to limit the function to only the new individual and edit on the backend?
Code: [Select]
function civicrm_postProcess( $formName, &$form ) {
//How do I use an if statement to select the backend individual new and edit form

//Telerivet API CONNECT
require_once JPATH_SITE.'/media/civicrm/telerivet/telerivet.php';
$API_KEY = 'apikey';
$PROJECT_ID = 'project id number';
$telerivet = new Telerivet_API($API_KEY);
$project = $telerivet->initProjectById($PROJECT_ID);



//Get Variables Civicrm
    $firstName = $form->getVar( 'first_name' );
        $lastName = $form->getVar( 'last_name' );
  $contactid = $form->getVar('contact_id');
$phone = $form->getVar('phone');
$displayName = $form->getVar('display_name');

   // Telerivet Post New Contact to Telerivet
    $contact = $project->getOrCreateContact(array(
    'name' => $displayName,
    'phone_number' => $phone,
    'vars' => array('first' => $firstName, 'last' => $lastName, 'civiid' => $contactid)
));

   
}
}

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Re: Sending Contact Information on Create/Update
July 31, 2014, 04:31:35 pm
It doesn't seem that I am getting the variables from the CiviCRM forms correctly.  Could anyone help with that?

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Re: Sending Contact Information on Create/Update
July 31, 2014, 08:27:27 pm
I now have it working  except I can't get the phone_numeric out of the phone array.  Any ideas?
Code: [Select]
function civicrm_post( $op, $objectName, $objectId, &$objectRef ) {
civicrm_initialize( true );
require_once 'CRM/Core/Config.php';
$config =& CRM_Core_Config::singleton( );

//Telerivet API CONNECT
require_once JPATH_SITE.'/media/civicrm/telerivet/telerivet.php';
$API_KEY = '------';
$PROJECT_ID = '-------';
$telerivet = new Telerivet_API($API_KEY);
$project = $telerivet->initProjectById($PROJECT_ID);
//CRM_Core_Error::debug($form);
//exit( );

//Get Variables Civicrm
    $firstName = $objectRef->first_name;
        $lastName = $objectRef->last_name;
 
$phone = $objectRef->phone->phone_numeric;
$displayName = $objectRef->display_name;

   // Telerivet Post New Contact to Telerivet
    $contact = $project->getOrCreateContact(array(
    'name' => $displayName,
    'phone_number' => $phone,
    'vars' => array('first' => $firstName, 'last' => $lastName)
));

   
}
}

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Re: Sending Contact Information on Create/Update
August 01, 2014, 09:19:41 am
I figured out the code to get the phone
Code: [Select]
    $firstName = $objectRef->first_name;
        $lastName = $objectRef->last_name;
 
$phone = $objectRef->phone[0]->phone;
$displayName = $objectRef->display_name;

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Sending Contact Information on Create/Update

This forum was archived on 2017-11-26.