You are here

Add Drupal 7 user role to a user when they complete a quiz using Quiz and Rules Modules

What I needed:

I needed a rule that assigned a user role to a user after they completed a certain quiz developed in the quiz module.  The reasoning behind adding this new role was we wanted users to complete one quiz before having access to the rest of the quizes on the site.

After researching like crazy here's what I came up with:

Event: Drupal is initialing

Condition: Check Path (In the Path section)

PATH TO CHECK: node/yourquizNID/quiz-results
COMPARISON OPERATION
Value:

contains
 

Actions: Add user role

Data selector: site:current-user
Roles : 'The role you want to add"

And that did it for me.

When the user submits their last question on that quiz and is directed to the quiz results page, the new user role is added. 

Drupal 7 Modules used:

https://www.drupal.org/project/pathrules

https://www.drupal.org/project/rules