Drupalwoo ☉

Building a Drupal registration form with custom fields

User registration becomes easier to manage when the form is part of the user data model, rather than extra inputs bolted onto the account page. Drupal can collect an organisation name, business number, phone number, account type, or address when someone creates an account. Those answers remain available to templates, email notifications, views, and other modules, so later workflows do not have to ask again.

This guide uses Drupal 10 and 11 features and starts with Field UI, included in core. It covers field creation, form placement, validation, conditional behaviour, privacy, and testing. Examples use Australian requirements because a form built in Sydney, Melbourne, or Brisbane may need an ABN, a +61 mobile number, clear consent choices, and compliance with the Australian Privacy Principles. The administration model works the same way elsewhere.

Plan fields and access rules

Begin with a field inventory rather than a visual layout. For every proposed item, record its purpose, operational owner, whether it is required, who may see it, and what happens after submission. A field added because it might be useful creates maintenance and privacy work. Splitting one idea into separate fields, such as account type and business status, usually makes filtering and validation more reliable.

Core manages the username or display name and email address. Custom fields should add information the account genuinely needs: organisation, ABN, job title, mobile number, preferred contact method, or consent status. Use stable machine names such as field_organisation and field_abn; they protect integrations when labels change.

Access decisions belong in the same plan. Decide whether visitors may register immediately, administrators approve accounts, and which role is assigned. Email verification can stop bogus accounts, while honeypot or CAPTCHA controls deserve consideration for public forms. Australian agencies often maintain Drupal sites for government, education, nonprofit, and corporate clients, so a documented approval trail and export-friendly structure can matter as much as quick sign-up.

Add fields to the user entity

In Drupal, open Structure > User fields and choose Add field. Choose the type before labels because it determines the available widgets and validation. Text, Email, Telephone, List, Date, Address, and URI cover many needs. Give each field a clear label, useful help text, and a machine name that will still make sense to developers.

Field settings control cardinality and input rules. Most profile attributes should allow one value; a multi-value field suits only independently meaningful entries. Set a realistic length limit for organisation names and avoid requiring data with no downstream use. The field attaches to the user entity, so it can also appear on profile and account-editing forms.

Field UI keeps this work in configuration, but a custom module helps when fields must be created consistently across environments. Deepali Gupta’s Drupal development notes can provide a useful external reference when weighing configuration against programmatic setup. Treat field definitions as version-controlled artefacts and include any schema changes in deployment steps.

Place fields on the registration form

Next, allow the intended people to register. At People > Account settings, enable visitor accounts, then review email verification, password, and cancellation settings. Wording varies slightly between Drupal versions, but the key decision is whether an account becomes active immediately or only after verification or administrator approval.

Open the User entity’s form-display settings and choose Register. Drag fields into order and configure their widgets: radio buttons for a short account-type list, a select for state or country, and plain text for an ABN. Set required status on this display rather than every account form, since an administrator-created account may need different information.

The core form ID is user_register_form, making it easy to target in hooks or tests. Keep sign-up focused on information needed to create and route the account; collect billing or qualification details later. Check duplicate-email messages, password confirmation, the final account message, and verification links. A layout change affects one display mode, so inspect register, edit, and admin-user layouts separately.

Add validation and conditional behaviour

Validation should explain errors where visitors can fix them. Drupal can enforce required values, length limits, option lists, and custom email rules. A business account needs more than a format check: an ABN has 11 digits and starts with 2, but that does not prove it is active. Use an Australian Business Register lookup when eligibility depends on a live ABN.

A small module can adapt the core form without changing its templates. This example shows the ABN field only for a business account and makes it conditionally required:

use Drupal\Core\Form\FormStateInterface;

function australian_site_user_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  if ($form_id !== 'user_register_form') {
    return;
  }

  if (isset($form['field_abn'])) {
    $form['field_abn']['#states'] = [
      'visible' => [
        ':input[name="field_account_type"]' => 'business',
      ],
      'required' => [
        ':input[name="field_account_type"]' => 'business',
      ],
    ];
  }
}

function australian_site_user_register_form_validate(array &$form, FormStateInterface $form_state) {
  $type = $form_state->getValue('field_account_type');
  $abn = preg_replace('/\s+/', '', (string) $form_state->getValue('field_abn'));

  if ($type !== 'business') {
    $form_state->setValue('field_abn', NULL);
    return;
  }

  if (!preg_match('/^2\d{9}$/', $abn)) {
    $form_state->setErrorByName('field_abn', 'Enter an 11-digit ABN beginning with 2.');
  }
}

The callback catches obvious mistakes but not the ABN checksum. States provide fast browser feedback, while server-side validation remains authoritative because JavaScript can be disabled or altered. Clear a hidden field when it no longer applies, as the example does. For larger dependency trees, evaluate a maintained conditional-fields module, checking its Drupal compatibility and security advisories.

Design an accessible Australian-friendly form

Accessibility is part of the form, not decoration. Give every control a persistent visible label, explain unfamiliar abbreviations, mark required fields in text as well as colour, and keep errors beside the relevant field. Support keyboard operation, visible focus, sufficient contrast, and touch targets around 44 by 44 CSS pixels. Placeholder text disappears as someone types, so it should not replace a label.

Set examples that match Australian expectations. Phone fields can show +61 and explain that local mobiles may begin with 04; date fields should present day, month, and year without an ambiguous numeric order. Address fields can restrict the country to Australia and offer NSW, VIC, QLD, WA, and other state codes. For event times, handle AEST and AEDT daylight-saving changes rather than a fixed UTC offset.

Consent deserves a separate decision. Account creation and marketing communication should not share one checkbox, and consent should not be pre-ticked. The Privacy Act 1988’s Australian Privacy Principles and the Spam Act 2003 call for careful collection, purpose disclosure, and consent-based electronic marketing, with unsubscribe mechanisms for marketing messages. Record the policy version and timestamp for evidence rather than an ambiguous yes or no. Direct Australian English will feel familiar: “We’ll email you shortly” is clearer than administrative phrasing, even where “fair dinkum” is common in conversation.

Compare field types and widgets

Field types define the data shape; widgets define how people enter it. A select list should hold a controlled category, while a text field can hold a name whose spelling Drupal cannot predict. Choosing a stronger type reduces custom validation and produces cleaner values for views, exports, and API-based workflows.

Compare the requirement, field type, widget, and setting before adding anything. An address, for example, provides state and postcode fields that a single text box would only imitate:

Registration need Core field type Suggested widget or setting Why it fits
Account category List (select) Radio buttons with stable values such as individual and business Supports reliable filtering and conditional logic
Organisation name Text Plain text with a sensible length limit Preserves official spelling without imposing a list
Australian business number Text ABN-specific server-side validation Keeps a numeric identifier separate from general text
Mobile contact Telephone Optional +61 example Accepts international punctuation while guiding entry
Address Address Australia restriction with a state list Structures postcode, locality, and state
Website URI URL validation Prevents malformed or unsafe link values

Some data belongs with the account, while other data needs its own entity. A billing address used for one transaction should not become a permanent user field if it will be replaced repeatedly. An organisation used across workflows belongs on the user. Avoid file uploads on public registration unless there is a clear need; they add storage, scanning, and access-control requirements better handled separately.

Test, launch, and maintain the form

Test the complete journey in a staging environment with an anonymous browser session. Create individual and business accounts, trigger every required-field error, try an invalid ABN, switch account types after entering a value, and confirm that the hidden value is cleared. Repeat the flow with keyboard navigation and a narrow mobile viewport. Check verification emails, administrator approval, assigned roles, and the resulting profile before production traffic arrives.

Deployment needs the same care as custom module code. Export field and form-display configuration for configuration management, deploy the module through the normal release pipeline, and include an update hook if a field definition requires a schema update. Never copy production user records into a public staging site; use synthetic details instead. After deployment, monitor registration errors, spam patterns, and abandoned submissions.

A stable registration flow treats each field as a governed piece of account data. With clear requirements, sensible Australian formats, layered validation, and repeatable tests, the form remains useful as the site and its community grow.