Conditional profile field

~ 0 min
2017-03-08 13:23

Conditional profile field is a profile field plugin developed and maintained by Foodle. This plugin enables administrators to add a special conditional drop-down menu field to the users' edit profile page. Based on the users' selections in the drop-down, other profile fields will be displayed or hidden. Also, based on the users' selection some fields may become mandatory.


You can download the plugin from You would need to put the plugin's files in a directory named conditional inside user/profile/field within your Moodle files. To learn more about installing new plugins or alternative ways of installation refer to Moodle Docs.

Adding a new user profile field

Once the plugin is installed, you can go to Site administration > Users > Accounts > User profile fields to add a new conditional field.

Just like any other custom profile field, the settings of a conditional field are divided into common settings and specific settings. Common settings include some settings such as name, description and whether the profile field is required or not. It is also possible to specify if you want the profile field to be displayed on the signup page.

Specific settings are done in 3 steps:

  • Entering menu options and optionally selecting an option as the default value
  • Configuring conditions to specify what fields should appear or hide or what fields are required for each menu option
  • Specifying whether all fields should be hidden initially or not (continue to read)

Specifying options

A conditional profile field is essentially a drop-down menu with some options that selecting each of its options may affect other profile fields. To specify the menu options, enter them one per line in the designated area. If you want one of the options to be selected by default, you can write its value in the "Default value" field. Please note that the value you put here must exist in the menu options list and exactly match one of the lines, so it is recommended to copy and paste its value from the list specified above rather than typing if again.

Configuring conditions

It is assumed that some other profile fields of any type have already been created and now you want to show/hide some of them using this conditional field.

Once you have entered available menu options, you can click on the "Configure conditions" button to specify which other profile fields must be shown or hidden or what fields should be required fields. The configuration dialogue does not allow you to set a field as required and hidden at the same time for the same option for obvious reasons!

As an example, if conditions are configured like the image above, and a user sets the conditional menu field to "Option 1", then fields 1 and 4 are shown (remain visible), and fields 2 and 3 become hidden. If the user selects "Option 2", fields 2 and 3 remain (will remain) hidden, but field 1 becomes (will become) a mandatory field which the user cannot leave it blank. If the user selects "Option 3" then all fields of 1 to 4 would be shown, and no field would be hidden.

Hide initially

As you have seen, specifying what fields are going to be shown or hidden is only by selecting the fields you want to hide. Therefore while a user has not yet selected any value for the conditional menu, no fields are removed (hidden) from the form and the user sees all available fields. Although what really happens is that some fields are removed from the form based on the conditional field's value, sometimes you want users to experience that fields are appearing based on their selection. If the "hide initially" setting is checked, all fields that are involved in being hidden or shown are becoming hidden when users have not selected any option yet.

For example using the previous image configuration, if the "hide initially" setting is checked and a user has not selected any of the options yet, then fields 2 and 3 would be initially hidden, and the user only sees fields 1 and 4. The reason that fields 1 and 4 are remaining is that according to configuration those fields never hide. Now if the user select option 3, what they observe to happen is that fields 2 and 3 are added to the form.

Required fields

When adding a new user profile field, you can specify whether the field should be a mandatory field or not. On the other hand, when using a conditional field, some other fields may be removed from the form depending on the value of the field. In the previous example, assume that you had set "Field 2" as a required field when you were creating it. Although Moodle tries to force users to enter a value for that field, the field will become hidden if users select any of "Option 1" or "Option 2" options. The conditional plugin can deal with this case that some required fields are hidden and saves submitted forms successfully.

But since Moodle 3.0.7 (in 3.0 family) and 3.1.3 (in 3.1 family) and 3.2 above, as a result of MDL-46946, Moodle forces users to complete required custom user profile fields. Moodle checks for incomplete required fields before displaying each page and redirect users to their edit profile page if there is any. Therefore although the conditional plugin itself deals with a required field being hidden, users will trap in an endless loop using mentioned Moodle versions.

Considering above note, never set a profile field as a required field if you want that field to be hidden in some situations. Instead, define that field as a field that may remain empty, and then while configuring a conditional field, you can choose what fields you want to be required for each selected option. In the previous example, "Field 1" is required when "Option 2" is selected by the user as the value of the conditional field.

Condition conflict

If you have created more than one conditional field, please pay extra attention that their condition configurations do not interfere with each other. Please make sure that users do not end up in a situation that a field is hidden and required at the same time.

Assume that the name of the conditional field in the previous example is "Conditional field 1".  Also, assume that you have configured another conditional profile field named "Conditional field 2" like beside image. If a user sets "Conditional field 1" to "Option 1" and "Conditional field 2" to "Item 3", then "Field 2" becomes hidden by "Conditional field 1" while being required by "Conditional field 2" according to its selected value. Similarly, if a user selects "Option 2" for "Conditional field 1" and selects "Item 2" for "Conditional field 2", then "Field 1" and "Field 2" will both become hidden and required at the same time.

Uninstalling the plugin

Uninstalling the conditional profile field plugin is similar to any other user profile field plugin. You need to remove any instances of conditional field you have added before being able to uninstall the plugin. To uninstall the plugin, go to Site administration > Plugins > Plugins overview and uninstall the conditional profile field plugin.

Average rating 4.79 (19 Votes)

You can comment this FAQ

Gergis (2020-09-03 11:25)
hello i have used your plugin, and formulated a lot of conditional fields, unfortunately; a conflict show morebetween hidden and required field happened, and now I cannot access the site as Administrator even to fix this issue any recommendations?????
Gergis (2020-09-03 11:26)
hello i have used your plugin, and formulated a lot of conditional fields, unfortunately; a conflict show morebetween hidden and required field happened, and now I cannot access the site as Administrator even to fix this issue any recommendations?????