How to Assign a Different Roles Based on Checkbox on User Registration Form

kellycee - February 4, 2009 - 21:52
Project:Workflow-ng
Version:5.x-2.1
Component:Wng API
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Issue tags:error, import, permissions, roles, rule, rules, user
Description

Hello,

Under User Management - Profiles, I have created a custom checkbox type field named "profile_over_age".

When a new site user registers for an account, if they select this checkbox, they will automatically be assigned a "teacher" role. If they do not select this box, they will automatically be assigned a "student" role. The User Settings are configured so that visitors can create accounts without administrator approval.

To accomplish this, I currently have two rules set up.

Rule 1 is invoked when "User has Registered".
The condition is a custom PHP code:

return $account->profile_over_age == "1"

The action is to "Add User Role"
The user whose role should be changed is "registered user".

Rule 2 is exactly the same except the condition is:

return $account->profile_over_age == "0"

This has not been working. No roles are assigned at all.

I've tried just putting in the condition as return $account->profile_over_age and having Rule 2 with the Negate box checked but this has not worked either. Instead, this gives the registered users both of the roles.

Would anyone be able to help?

Thank you

#1

mrvinceo - September 10, 2009 - 11:16

Hi,

Have you made any progress with this? I'm having a similar problem, but related to an import of 'course codes' from our student database which is intended to tie into matching roles e.g. If course code = PH1AOP assign user to a pre-made PH1AOP role. I'm using an Execute Custom php code condition to run this rule when an account is updated:- return $account->profile_course_code1 == "PHA01";

The rule operates, but the user is assigned to several roles - not just the one selected in the rule. I'm coming down with a headache with this. I've tried the textual comparison, but I keep getting errors through this route. I confess I'm not very php savvy...

 
 

Drupal is a registered trademark of Dries Buytaert.