3

I have a scenario - which I have no doubt that others will have come a crossed and some will have implemented. The scenario is: to have a web form (created via the Webform module - which has CiviCRM fields integrated into it - via the Webform integration module) that has the CiviCRM fields such as:

  • the first name,
  • the last name,
  • the e-mail address, and
  • the address (e.g. address line 1, address line 2, city, post code) etc

and when the user (whom is not logged in - as they do not have a Drupal account) selects submit

  1. The details entered are saved in CiviCRM, but equally
  2. A Drupal user is created for the user (no doubt using the Rules module in Drupal).

The issue is that

  1. I’d only want the rule fired if the web form was used, not if I create users via the CiviCRM admin interface (as I have sub-type contacts which wouldn’t need Drupal accounts assigned to them)

  2. When I go into Rules - I can find the triggering event, which i assume would be “CiviCRM Contact: Contact has been created” e.g. when a Contact is created the rule will begin to fire…

enter image description here



what I’m not sure about is:

2a. how to configure the condition for the rule to say “only do the action if the contact is of sub-type x” or if triggered by webform x

2b. how to configure the action portion of the rule to create a new Drupal user

2)b)i. there is the “Create a new entity” option under the Entities section in the drop down for action to add, where i can choose “User” as the value …

Image 2: The rules screen - where trigger specified in top section

enter image description here

Image 3: The options user the actions options

enter image description here


however, on the next screen - where it asks for the login name of the user, the replacement patterns do not provide me with a means of saying use the e-mail entered in the registration form as the User name for the account that I want created; nor does it allow me to specify that the system should pick up the e-mail entered in the web form as use that as the email address for the new account being used.

  • side note: I do realise at this point having written the above that the rule was written saying do x when event y is triggered - and without specifying that event y should be coming from webform a, which might explain why the action portion of the rule is not providing any replacement pattern for the username - e.g the rule is generic so would be fired if a contact record was created via a different form or the general CiviCRM admin panel.

So… anyone got any ideas on how to achieve what I’m trying to do above? I assume I can do the above without having to get involved with writing bespoke modules or using hooks etc.

1
  • Ok it looks like I can use the Webform Rules module to restrict the firing of an action to a Webform ... this might address aspect 2)a) in the question...
    – Mo-ster
    Nov 24, 2017 at 12:18

2 Answers 2

2

Most of what you need is here: How can I create a Drupal user when someone submits a CiviCRM-Webform? based on @petednz-fuzion's blog post. It uses civicrm_entity which has seen a lot of activity since the previous question so there may be some changes but hopefully nothing that prevents you following it.

For limiting action to a specific contact sub-type, add a new Condition using 'Data comparison' with a data selector of civicrm-contact:contact-sub-type

1
  • Hi Aidan... Thanks for the info and taking the time to look into the issue I am having... an interesting approach will see if it resolves my issue in totality... on a side note: since posting my question I was able to use create entity - then select User to create a Drupal user - however, it only seems to work when I statically assign the username and e-mail values not when I tell it too use the values provided in the form fields e.g. [data: {component}-value]
    – Mo-ster
    Nov 24, 2017 at 13:54
2

Ok so the installation and use of the Webform Rules went a long way to contributing to resolve the issue in terms of restricting the triggering of the action of creating a user and also providing the webform fields to the rule process...

And Aidan's info seemed like a possible solution and provided another way of doing things (but, I think, as pointed out by Aidan a lot has moved on since that information was published and so some of the options are no longer available in their former guise).

... Then there was info from @Pierre.Vriens see the thread posted here:

Webform Rules - Create a Drupal User

... where the recommendation was to try and use variables to hold the field values and then assign the variable as the value of the Drupal User Entity, which I did and it resolved the second part of the issue.

Thanks to both @Aidan and @Pierre.Vriens for the help on this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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