2

I have a simple Drupal webform that is integrated with Civi and creates a tagged contact. I use the approach described by @petednz at https://civicrm.org/blog/petednz/creating-drupal-users-made-easy-for-single-or-multiple-contacts-via-civi-imports-and to create a Drupal user and log them in when the form is submitted. In my case this then gives them access to a larger form where I want them to be able to save a draft and return later, hence the need for the user account.

Here's the rule that I'm using:

{ "rules_friends_tag_account_create" : {
"LABEL" : "Self Create User Account and login",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "CiviCRM", "CiviCRM User" ],
"REQUIRES" : [ "civicrm", "rules" ],
"ON" : { "civicrm_entity_tag_create" : [] },
"IF" : [
  { "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm-entity-tag:entity-id-contact" ] } },
  { "data_is" : {
      "data" : [ "civicrm-entity-tag:entity-table" ],
      "value" : "civicrm_contact"
    }
  },
  { "data_is" : { "data" : [ "civicrm-entity-tag:tag-id" ], "value" : "6" } }
],
"DO" : [
  { "civicrm_entity_action_create_user" : {
      "USING" : {
        "civicrm_contact" : [ "civicrm-entity-tag:entity-id-contact" ],
        "is_active" : "1",
        "notify" : "1",
        "signin" : "1",
        "username_format" : "first last"
      },
      "PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created Drupal User" } }
    }
  },
  { "user_unblock" : { "account" : [ "civicrm-user" ] } },
  { "user_add_role" : { "account" : [ "civicrm-user" ], "roles" : { "value" : { "7" : "7" } } } }
]

} }

This has been working reliably for some months, and seems rock solid when I test it.

However I'm seeing behaviour from users that suggests that it isn't working all the time: i.e. sometimes I see that they have submitted the first form two or three times in quick succession, suggesting that they are not reaching the second form, but getting an access denied message instead, which is what would happen if the user account wasn't created for them.

Also, in recent days, I've seen on two or three occasions now the following error message in the Drupal log:

Unable to get variable civicrm_user, it is not defined.

Why might this rule be working fine for much of the time, but not consistently? How can I debug this? Is there a more robust approach that I could take?

  • Have you changed versions of something since this was working well? – petednz - fuzion Mar 13 '17 at 23:58
  • ""username_format" : "first last"" looks like it is the culprit in some cases at least. Users being human are adding a space after their first name and then Drupal complains that it can't have multiple consecutive spaces in a username. Got round that one by changing to use email address as the username. – Graham Mar 15 '17 at 12:21
  • 2
    oh right. on a webform could you have validated the field with webform_validation. worth adding yours, or this, as an answer? – petednz - fuzion Mar 15 '17 at 17:52
0

You can register users through Webform Registration module. This module allows maximum flexibility to control the user registration process.

  • Hi Hassan, can you confirm that this results in the Drupal user being connected to the civi record? Also the modules says "Development version: 7.x-1.x-dev updated 10 Nov 2015" so seems to be largely unmaintained. – petednz - fuzion Jan 4 '18 at 21:57
  • Yes , i have tested the connectivity of drupal user with civicrm contact that gets created through that module. I understand your concern and i agree that this module is not well maintained and do not have any security release yet. I am afraid you would have to review the code base for any vulnerabilities. – Hassan Farooq Jan 8 '18 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.