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
- Log in to your Developer Portal as an administrator.
- Navigate to Manage fields tab. and click the
Manage fields
tab.- Click + Create a new field.
- In the
Select a field type
dropdown, select Text (plain), and click Continue. - In the
Label
field enter, Department code, and select Text (plain). - Click Continue.
Department code settings for user
page.- Accept the defaults of
Maximum length
(255) andAllowed number of values
(Limited:1). - Click Save settings.
Manage fields
page. Check that Department code
is a listed field.- Under
Label
, findDepartment code
and click Edit. - Add some help text. This is information that is displayed to the user to assist them 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.
- Add Example department code: DEP123. into the
Help text
field. - Select the Required field checkbox.
- Click Save settings.
The field has now been created. You are back on the Manage fields
tab.
Adding the new field to the Sign up form
- Switch to the Register tab. Notice that initially the new
Department code
field is underneath theDisabled row
in the page. This means that it isn't shown on the form. - Click the Department code icon and drag it so that it is between Last name and Consumer organization in the list.
- Click Save.
Testing the new field
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.