Tutorial: Adding a field to the sign up form

You might want to collect and store additional information about your Developer Portal users. For example, you might want to collect a department name, employee ID, or similar data when a user registers for an account on the portal.

Before you begin

You must have a Developer Portal enabled, and you must have administrator access to complete this tutorial. The tutorial Creating the Portal explains how to enable the portal if you have not already done so.

About this tutorial

In this tutorial, you will add a Department code field to the Sign up form. This field is required for all portal users.

Adding a field to a user entity

  1. Log in to your Developer Portal as an administrator.
  2. Navigate to Configuration > People > Account settings > Manage fields
You are on the Manage fields tab.
  1. Click + Create a new field.
  2. Under the Choose a type of field section, select Plain text and click Continue.
  3. In the Label field enter, Department code.
  4. Select Text (plain) from the available options.
  5. Click Continue.
You are on the Edit tab.
  1. Under Field Storage, ensure the following default values are selected:
    • Maximum length: 255
    • Allowed number of values: Limited and 1.
  2. In the Help text field, add some details. This text is displayed to the user to assist them in completing the field on a form. Examples or links to further information are useful here. We are going to add an example in this tutorial: enter Example department code: DEP123 in the Help text field.
  3. Select the Required field checkbox.
  4. Click Save settings.

The field has now been created.

You are now on the Manage fields tab and can find the Department code label in the Field list.

Adding the new field to the Sign up form

  1. Navigate to Configuration > People > Account settings > Manage form display
You are on the Manage form display tab. These tabs, one for each form, show the fields that are displayed from the user entity, and in which order.
  1. Click the Register tab. Notice that initially the new Department code field is under the Disabled row section. This means that it isn't shown on the form.
  2. Select Content from the Region column to move Department code to the top of the list and show it on the form.

    Page showing the Department code field

  3. Click Save.

Testing the new field

  1. Sign out as the Admin user.
  2. Click Create account.
  3. Observe that the Department code field is now part of the sign up form.

What you did in this tutorial

You added a Department code field to the Sign up form, then tested the form to ensure that the Department code field is now part of the sign up form.

In reality, you would need to add this configuration in such a way that it is available for all sites. To achieve this you would include the configuration in your custom module. For more information, see this Drupal documentation.

You might want to add extra validation to the Department code field on the Sign up form. For more information, see Tutorial: Adding validation to a field on the sign-up form.