Show or Hide Form Fields Based on User Joomla User Group

Have you ever needed to show or hide a form field based on a user’s group or access level? Maybe you only want to require a CAPTCHA for guests while improving the experience for logged-in users. Or perhaps you’re running a listings site and wish to restrict image uploads to registered members. Maybe your form is only accessible to logged-in users, but you want to display a special field exclusively for those in a specific user group.

Let's see how we can make this happen with Convert Forms.

Step 1: Create a Hidden Field to Store the User Groups

The first step is to add a hidden field to our form to hold user group information.

Hidden%20Field%20that%20Autopopulates%20Joomla%20User%20Groups

  1. Go to the All Fields tab.
  2. Click to add a Hidden Field.
  3. Set the name of the field to "usergroups".

Now, let's add a bit of magic to the hidden field. For the Default Value setting, we will use a Convert Forms Smart Tag to populate the user's groups, {user.groupTitles}. This Smart Tag returns the titles of the user groups comma-separated. Eg: Public, Registered. 

Hidden%20Field%20with%20Joomla%20User%20Groups%20Smart%20Tag

If the user isn't logged in, it will return the default groups for a guest user, which in most cases are "Public, Guest".

If you believe the names of the user groups are a bit personal and sensitive information, you can use the Smart Tag {user.groups} which returns the ID of each group assigned to the user. Eg: 1,2,5.

Step 2: Apply Conditional Logic to Other Fields Based on the User Groups Hidden Field

Suppose our form includes a CAPTCHA field, but we only want to show it to guest users while allowing logged-in users to submit the form without it.

Newsletter%20Subscription%20Form%20for%20Joomla

To achieve this, we’ll use Conditional Fields to check the value of the hidden field created in Step 1. If the value contains “Guest” which is the default user group for non-logged-in users, the CAPTCHA field will be displayed. Otherwise, the field will remain hidden if the user is logged in.

Show%20or%20Hide%20CAPTCHA%20field%20based%20on%20User%20Groups

Go to the Behavior tab and click Setup Conditions in the Conditional Fields panel.

  1. Click Add Condition
  2. In the 1st dropdown select the User Groups hidden field you created in the first step.
  3. Set the Operator to Contains
  4. Set the value to "Guest". 
  5. Next, in the Do section, select the CAPTCHA field you want to hide.
  6. Set the Action option to Hide field.
  7. In the If the condition is not met section, select again the CAPTCHA field.
  8. In the Action option now select Show field

This conditional logic would read in plain English: "Display the CAPTCHA field if the UserGroups hidden field contains ‘Guest’; otherwise, keep it hidden".

Summary

The same approach can show or hide fields based on a user’s access levels instead of user groups. In this case, you can use the Smart Tags {user.authLevels} and {user.authLevelTitles}, which return the IDs and titles of the user’s access levels as a comma-separated list. By applying conditional logic to these values, you can control field visibility based on specific access levels, offering greater form flexibility.

Last updated on Mar 5th 2025 10:03