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) »
  • Create a contact and add to a group with postProcess
Pages: [1]

Author Topic: Create a contact and add to a group with postProcess  (Read 554 times)

petermcandrew

  • I’m new here
  • *
  • Posts: 15
  • Karma: 4
    • The Green Party
  • CiviCRM version: n/a
  • CMS version: n/a
  • MySQL version: n/a
  • PHP version: n/a
Create a contact and add to a group with postProcess
January 30, 2012, 02:39:35 am
I'm trying to create a contact from some custom fields on a contribution page and then add them to a group.

My problem it figuring out the contact ID of the new contact.

I've written a function which takes contact ID and birth date (to do some validation) as parameters.

But I'm not sure how I can find out the ID of a contact that I've just created using postProcess, in order to call the function.  Is this possible?

Thanks!
Peter McAndrew
The Green Party

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Create a contact and add to a group with postProcess
January 30, 2012, 03:03:16 am
If you created the contact using an api call then

$result = civicrm_api('contact','create', $params);
$contact_id = $result['id'];
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

petermcandrew

  • I’m new here
  • *
  • Posts: 15
  • Karma: 4
    • The Green Party
  • CiviCRM version: n/a
  • CMS version: n/a
  • MySQL version: n/a
  • PHP version: n/a
Re: Create a contact and add to a group with postProcess
January 30, 2012, 10:00:11 am
Hey Eileen thanks,

In fact I'm creating two contacts (primary and joint) the joint one through the API (so can use what you suggested) the other not.  So still need to find out the ID of the primary contact that gets created via the contribution page, any thoughts on that?

Cheers
Peter
Peter McAndrew
The Green Party

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Create a contact and add to a group with postProcess

This forum was archived on 2017-11-26.