Newsletter subscription in CIVICRM 4 – Drupal 7 combo

LeviaIT recently got me working on a very exciting project, modifying CIVICRM – Drupal combo to work for a certain niche market. And while i heard and read about CIVICRM before this was the first time working with it. Everyone talks about CIVICRM and Drupal working nicely together, that it up to the point of them actually “working” together… 🙂

So one of the issues i came upon was lack of subscription form for the newsletter module built in in the CIVICRM. The inherent issue was more then just a missing form for integration, since CIVICRM newsletter module is meant to track who you send the newsletters to and what happens after that… that means that if anonymous user wants to signup to the newsletter, he would / should force him to fill out the full registration form first, which would be doable, but really annoying.  So i wanted to share our solution:

  1. Add a custom field in user, with a yes / no selection (could be done by going to yoursite.com/civicrm/admin/custom/group?reset=1 )
  2. Next step is to create a smart group (smart groups automatically add users to a group based on a search criteria), based on if the value for “Receive the Newsletter” is “Yes”.
  3. Create a new webform with an email field. (check what the webform id is you will need it for the next step)
  4. write a custom drupal module to do the rest of the magic. (explained below)

Now lets get to the module part:

As usual the first step is to create the hooks.info file:

Next is the hooks.module file:

Please be aware though that there is a couple of variables that you will need to find in your civicrm database and substitute those values in the code the list is as following:

  1. Webform ID as mentioned above – in my example the is was “webform_client_form_8”
  2. Look into database to find out the name of the table where the values for our custom nesletter field are stored – in our example the table name is “civicrm_value_subscribe_to_newsletter_18”
  3. In the above table the last collumn will be called something like this – “would_you_like_to_receive_our_ne_69”

Now all you need to do is substitute these values with values from your CIVICRM database, upload and activate the module. Your newsletter webform is ready! 🙂

, , , , , , , , ,

Related Posts

6 Comments. Leave new

  • Joffrey Parisot
    March 23, 2012 4:07 am

    Hi,

    It seems to be a great idea.
    And what if you create a settings adminsitration page to choose the webform and fields, so that you don't have to modify your code everytime ?

    Reply
    • Thanks for leaving a comment. That would be a great addition to this module of course, If someone would pay me to do it… hmmmm… 🙂
      If i have some time over the next month, maybe i will do it and then be able to upload it to the contrib section in Drupal and CiviCRM websites. Did you make any Civi websites?

      Reply
  • I was looking for a solution like that for the past few weeks… Thanks! 🙂

    Reply
  • Hiii, its good that you are using combo for newsletter subscription, i am also one of the users who faces few problems regarding subscription…. so is there a possibility to subscribe a newsletter as a guest an even you can maintain a database of this type of users. In addition can you able to add different fields or categories so we can go for categorize newsletter as per our needs and on weekly basis?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu