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) »
  • hook_civicrm_post usage Drupal 5.6, Civicrm 2.0.4
Pages: [1]

Author Topic: hook_civicrm_post usage Drupal 5.6, Civicrm 2.0.4  (Read 5301 times)

yasheshb

  • I post occasionally
  • **
  • Posts: 72
  • Karma: 5
hook_civicrm_post usage Drupal 5.6, Civicrm 2.0.4
October 22, 2008, 02:07:53 am
Hello:

    I'm working on the following problem (Drupal 5.6, CiviCRM 2.0.4). When a user signs up as a drupal user
   www.example.com/user/register

    They are displayed the name and address fields and a checkbox to signup for a newsletter. Now since we'll be
using CiviCRM to store the addres fields and the newsletter signup preference for the user, we decided to store it as a CiviCRM profile.

   Hence we created a basic CiviCRM profile which accepts name, address and newsletter signup preference for a new Drupal user.
   This profile group comes up on the drupal user registration page and things work fine when i create the new drupal user.

   However, what i want to do is if the user has selected the checkbox for newsletter subscription, i'd like to add them to a CiviCRM group.
   To achieve this i tried to access the civicrm profile fields in the drupal user hook but it seems civicrm profile fields don't show up in the
   drupal user hook.

   So next i tried the hook_civicrm_post but that is not invoked. Is there any way to solve this problem ? I used drupal profile fields and they
   did show up in the drupal user hook. Any clean way to solve this problem ?

Thanks.

Yashesh

yasheshb

  • I post occasionally
  • **
  • Posts: 72
  • Karma: 5
Re: hook_civicrm_post usage Drupal 5.6, Civicrm 2.0.4
October 22, 2008, 02:12:40 am
i looked at the advanced settings for the profiles

'Add new contacts to a Group? - Select a group if you are using this profile for adding new contacts, AND you want the new contacts to be automatically assigned to a group.'

but that is a blanket solution i.e. it'd add all contacts rather than those whose who selected Yes for subscribing to newsletter.

yashesh

yasheshb

  • I post occasionally
  • **
  • Posts: 72
  • Karma: 5
Re: hook_civicrm_post usage Drupal 5.6, Civicrm 2.0.4
October 22, 2008, 03:37:26 am
i was able to get the hook invoked finally (don't know what fixed it but i disabled/enabled the module) and it worked fine. however,
the custom field (i checked when objectName = Profile) is as follows

Oct 22 15:53:17  [info] entering function civitest_civicrm_post() in civitest.module
Oct 22 15:53:17  [info] $op = edit
Oct 22 15:53:17  [info] $objectName = Profile
Oct 22 15:53:17  [info] $objectId = 113
Oct 22 15:53:17  [info] $objectRef = Array
(
    [qfKey] => c59149909b4d5fea7b2789e4d6c7c2fb
    [edit] => Array
        (
            [civicrm_dummy_field] => CiviCRM Dummy Field for Drupal
        )

    [first_name] => neha
    [last_name] => bhatia
    [supplemental_address_1-Primary] => 21, Ashirwad
    [supplemental_address_2-Primary] =>
    [city-Primary] => Mumbai
    [postal_code-Primary] => 400056
    [state_province-Primary] => 1000
    [custom_6] => Array
        (
            [1] => 1
        )

)

Now the field is custom_6 which i'm interested in but the custom field id's change on devel, staging and production boxes :( . is there any way to specifiy the name of the custom field (like in drupal cck fields ?) so instead of custom_6 - custom_subscribe_to_newsletter ?

Thanks.

Yashesh


Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: hook_civicrm_post usage Drupal 5.6, Civicrm 2.0.4
October 22, 2008, 07:19:48 am

currently not, but a contribution to do this would be great

the first step would be to write a simple function that converts

custom_subscribe_to_newsletter to custom_6 (based on the values in the db etc).

Minor issue is custom fields in different groups could have the same name. so maybe use a format that includes field name and group name?

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: hook_civicrm_post usage Drupal 5.6, Civicrm 2.0.4
October 22, 2008, 09:43:28 am
Another possible approach here is to expose the "Group(s)" field in your profile and set your Newsletter Subscriber group as a Public group of type = Mailing List.
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • hook_civicrm_post usage Drupal 5.6, Civicrm 2.0.4

This forum was archived on 2017-11-26.