I have created 2 profiles with using profile2 for users lets name them A and B. All users will have role authenticated when they subscribe and will have to fill profile A. Then after completing subscription they can become "Pro" user by filling profile B fields. Now I want to change the user role when he fills this profile to "Pro". I was thinking about doing this with rules but couldn't make it up until now. What is the best way to do this?

2 Answers 2


This is doable with Rules:

  • Create rule that reacts on two events: 'After updating an existing profile' and 'After saving a new profile' - both are necessary because at some point, users might not have the profile created yet.
  • Add conditions to see if all fields are filled in (use "Data comparison", "Data value is empty" or "Text comparison" conditions and their negations based on what type of fields you have)
  • If all the conditions are met, give the role to the user with action "Add user role".

Btw. you do not have to worry if the user already has this role, it will not cause any unwanted behaviour if it is assigned several times.

  • I've used the "Data value is empty" and negated it on a required filed, so if the field is not empty the user's role should be change to "Pro". but when a registered user files the form for the first time and saves it, the rules not working, but when he saves the profile for the second time it works. what am I missing here?
    – lameei
    Commented Jan 31, 2014 at 18:01
  • Go to 'admin/config/workflow/rules/settings' and turn 'Show debug information' to 'Always' - then try to see what is wrong (or possibly paste the debug here)
    – m1n0
    Commented Jan 31, 2014 at 21:31
  • There is no errors on the page. here is the rules export pastebin.com/kxRZDWaa
    – lameei
    Commented Jan 31, 2014 at 21:48
  • Rules export is not helping here in any way - turn on the debug information as I described above, go through the profile saving process and after saving the profile, there will be a rules debug - paste that, together with detailed steps that you went through
    – m1n0
    Commented Jan 31, 2014 at 22:11
  • edited a registered user and filled the required field then saved the profile. Here is the error "Warning: Invalid argument supplied for foreach() in element_children() (line 6399 of /Users/mostafalameei/Sites/senda/includes/common.inc)." When I hit the save again, I see this warning but the rule works.
    – lameei
    Commented Feb 1, 2014 at 5:12

Here is the solution:

  1. Add an action for "After Creating a new profile"
  2. Add data comparison for profile2:type
  3. Check to see if it is equal to [Profile Type]
  4. Then add an action to change the user role. And here is the export of the rule:

    { "rules_become_pro_new_profile" : { "LABEL" : "Become Pro new profile", "PLUGIN" : "reaction rule", "OWNER" : "rules", "REQUIRES" : [ "rules", "profile2" ], "ON" : { "profile2_insert" : [] }, "IF" : [ { "data_is" : { "data" : [ "profile2:type" ], "value" : "pro" } } ], "DO" : [ { "user_add_role" : { "account" : [ "profile2:user" ], "roles" : { "value" : { "5" : "5" } } } } ] } }

Your Answer

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

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