I have a webform where there are conditional elements that are reliant on the user being a bona fide affiliate of our organisation. Both Anonymous and Authenticated users can use this form.

I currently have it using the CiviCRM elements to look for an existing contact in order to fulfill the conditional; however we have found that if we have had contact with the user (ie they previously were bona fide, or have submitted other forms in the past) then the conditional is fulfilled.

(Yes, that is kind of obvious.... we overlooked it)

I think I have three options;

  1. Have a webform field, hidden, pertaining to the user role. this can then be used as a conditional.
  2. Use a Workflow Rule to redirect users with particular roles to a different, but identical, webform. Then I would have two webforms each witht eh appropriate elements.
  3. Completely remove the connection to CiviCRM for the webform and rely on our staff to filter the wheat from the chaff.

Option 1 is probably the most logical solution in my mind, but I can not find a way to poll Drupal for the user role.

  • So if I understand correctly, you want to check if the user is Authenticated show one form/fields, if Anonymous show another form or fields? Commented Jan 10, 2017 at 15:40
  • Yes that is correct, although the roles we use are named Commented Jan 11, 2017 at 16:28

1 Answer 1


I'd recommend using hook_form_alter and user_has_role in a custom module. It allows you to alter the form programmatically and perform logic in your hook function so you can access your user's role and modify your fields that way. For example, you could do something like:

function yourmodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id=='your_form') {
     global $user;
     if (user_has_role(your_rid)){
       // add the extra field you need here

there are many examples on how to modify/add fields in the hook docs link above, plus you can google more tutorials on that.

  • Thanks for your thoughts. I just want to leave a quick note as I am going to need to find time to investigate custom modules (the website I mind as a volunteer - complete tangent to my day job!) - something I like to try avoiding! Commented Jan 14, 2017 at 16:14

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.