# Theme an Advanced Registration Form

Learn how to add labels, placeholders, error messages, and hidden fields to an advanced registration form with a custom theme.

> For the index of this section of the site, see [llms.txt](https://fusionauth.io/docs/llms.txt)

A theme controls how the hosted login pages render an advanced registration form. In this guide, you add readable labels, placeholders, and error messages to the form from the [Advanced Registration Forms Tutorial](https://fusionauth.io/docs/users/register/advanced-registration-forms/tutorial.md). You manage the theme messages with the API, so you can keep the messages in version control. You can make the same changes in the Admin UI.

For everything else a theme can change, see [Themes](https://fusionauth.io/docs/theme.md).

## Prerequisites

*   The real estate registration form and Application from the [tutorial](https://fusionauth.io/docs/users/register/advanced-registration-forms/tutorial.md).
*   FusionAuth at `http://localhost:9011`. When FusionAuth runs elsewhere, change the URLs in the scripts.
*   [jq](https://jqlang.github.io/jq/) and Python 3 on your computer.

## Create a Theme

The default theme is read-only, so create a copy. FusionAuth assigns themes per Tenant. You can change the theme of the [Default Tenant](https://fusionauth.io/docs/concepts/plans-and-limits/limitations.md#default-configuration), or create a new Tenant with a new theme. This guide changes the theme of the Default Tenant.

1.  Go to Settings -> API Keys and add an API key. Allow at least every method on the `/api/theme` endpoint.
    
2.  Go to Customizations -> Themes and duplicate the default FusionAuth theme. Name the copy `Real Estate Application`, and save the theme.
    
3.  Copy the Id of the new theme from the list of themes. The Id is a UUID, such as `42968bbf-29af-462b-9e83-4c8d7c2d55cf`.
    
4.  Go to Tenants and edit the Default Tenant with edit. On the General tab, set **Theme** to `Real Estate Application`, and save the Tenant.
    
    ![The Theme setting on the Default Tenant, with the new theme selected.](https://fusionauth.io/img/docs/screenshots/register-update-theme-for-tenant.png)
    

## Add Labels, Placeholders, and Error Messages

The theme messages hold placeholders, labels, validation errors, and other text for users. FusionAuth stores the messages in Java properties format in the **`defaultMessages`** field of the theme. The default theme renders a label and a placeholder for each field. Both come from the message whose key matches the field key, such as `registration.data.minprice`. When a theme has no message for a key, the form shows the key.

The following scripts download and upload the messages. The scripts are also in the [theme management repository on GitHub](https://github.com/FusionAuth/fusionauth-theme-management).

1.  Save the following script as `convert.py`. The script turns the escaped newlines from the API into real newlines:
    
    ```python
    import sys
    
    OUTPUT = sys.stdin.read()
    formatted_output = OUTPUT.replace('\\n', '\n')
    print(formatted_output)
    ```
    
2.  Download the messages to `defaultmessages.txt`. Replace `<your api key>` with your API key and `<your theme id>` with the theme Id:
    
    ```shell-session
    $ API_KEY=<your api key> && \
    THEME_ID=<your theme id> && \
    curl -H "Authorization: $API_KEY" 'http://localhost:9011/api/theme/'$THEME_ID|jq '.theme.defaultMessages' |sed 's/^"//' |sed 's/"$//' |python3 convert.py > defaultmessages.txt
    ```
    
    The command downloads only the messages. You can extend the command to download other theme fields. The file has about 200 lines and starts like the following excerpt:
    
    ```plaintext
    #
    # Copyright (c) 2019-2020, FusionAuth, All Rights Reserved
    #
    # Licensed under the Apache License, Version 2.0 (the \"License\");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    #   http://www.apache.org/licenses/LICENSE-2.0
    
    # ...
    
    # Webhook transaction failure
    [WebhookTransactionException]=One or more webhooks returned an invalid response or were unreachable. Based on your transaction configuration, your action cannot be completed.
    ```
    
3.  Open `defaultmessages.txt` in a text editor, and find the section that starts with `# Custom Registration forms`. Add a message for each field. Each key must match the key of a Form Field:
    
    ```properties
    # ...
    user.firstName=Your first name
    user.mobilePhone=Your mobile phone num
    registration.data.minprice=Minimum home price
    registration.data.maxprice=Maximum home price
    registration.data.geographicarea=Where are you looking?
    # ...
    ```
    
    The file isn't an `.ini` file, so FusionAuth ignores the sections. Keep your changes small and in place anyway. FusionAuth updates add new messages, and you must merge the new messages into your copy.
    
4.  Find the section that starts with `# Custom Registration form validation errors`, and add error messages for the price fields:
    
    ```properties
    [invalid]registration.data.minprice=Please enter a number
    [invalid]registration.data.maxprice=Please enter a number
    [missing]registration.data.minprice=Minimum home price required
    [missing]registration.data.maxprice=Maximum home price required
    ```
    
    An error message key has the form `[errortype]fieldkey`. The `Default validation errors` section lists the error types. The price fields have the `Number` data type. FusionAuth returns `invalid` when the value isn't a number, and `missing` when the value is empty. For every error code, see [User Data Validation](https://fusionauth.io/docs/users/user-data-validation.md#custom-form-fields).
    
5.  When a message contains a double quote, escape the quote as `\"`. The upload script sends the file as a JSON string, and an unescaped quote makes the API call fail.
    
6.  Save the following script, and run the script in the directory with `defaultmessages.txt`. The script converts the file to JSON and updates the **`defaultMessages`** field of the theme:
    
    ```shell
    API_KEY=<your api key>
    THEME_ID=<your theme id>
    
    FILE_NAME=out.json$$
    
    awk '{printf "%s", $0"\\n"}' defaultmessages.txt |sed 's/^/{ "theme": { "defaultMessages": "/' | sed 's/$/"}}/' > $FILE_NAME
    
    STATUS_CODE=`curl -XPATCH -H 'Content-type: application/json' -H "Authorization: $API_KEY" 'http://localhost:9011/api/theme/'$THEME_ID -d @$FILE_NAME -o /dev/null -w '%{http_code}' -s`
    
    if [ $STATUS_CODE -ne 200 ]; then
      echo "Error with patch, exited with status code: "$STATUS_CODE
      exit 1
    fi
    
    rm $FILE_NAME
    ```
    

To confirm the change, open the registration URL in a private browser window. The fields show the new labels and placeholders:

![The first registration step, with a label and a placeholder on each field.](https://fusionauth.io/img/docs/screenshots/register-first-step-with-placeholder-and-labels.png)

Submit the second step with an empty price to see the new error message.

## Change How Fields Render

The `customField` [FreeMarker macro](https://freemarker.apache.org/) in the theme builds the HTML for each field. The macro checks the control and data type of each field and renders the matching element. For example, a field with the `Password` control renders as an `input` element of type `password`.

To change the HTML of a field, go to Customizations -> Themes , edit your theme, and open Helpers . The `customField` macro is near the end of the template. The macro builds the element Id from the field key and replaces each period with an underscore. The form processing logic expects that Id format.

You can use FreeMarker, message bundles, CSS, and JavaScript to customize and localize the pages. For more information, see [Advanced Themes](https://fusionauth.io/docs/theme/advanced-themes.md).

## Add a Hidden Field

A hidden field captures data that the user doesn't type, such as a referrer.

1.  Create a Form Field for the value, such as `user.data.referrer` with the `Text` control.
    
    ![The Add Form Field page for a hidden field.](https://fusionauth.io/img/docs/screenshots/register-hidden-field.png)
    
2.  Add the field to the registration form.
    
3.  In the `customField` macro in Helpers , render a hidden input for the field key:
    
    Generating a hidden field
    
    ```ftl
    [#if field.key == "user.data.referrer"]
      <input id="user_data_referrer" type="hidden" name="user.data.referrer">
    [/#if]
    ```
    
    Keep the macro from rendering the visible input for the same key. The Id replaces each period in the key with an underscore, as the form processing logic expects.
    
4.  Set the value of the field with JavaScript in the theme:
    
    Setting a hidden field
    
    ```javascript
    document.getElementById("user_data_referrer").value = "value";
    ```
    

To confirm the result, register a user and open the User data tab of the user in the Admin UI. The tab shows the referrer value.

Related

[Users Build an Advanced Registration Form Learn how to build a two-step advanced registration form with custom fields, register a user, and read the custom data with the API. advanced registration formscustom registration](https://fusionauth.io/docs/users/register/advanced-registration-forms/tutorial.md)

[Users Advanced Registration Form Reference Reference for advanced registration form fields, validation, form rules, consents, localization, and edge cases such as required fields added later. advanced registration forms](https://fusionauth.io/docs/users/register/advanced-registration-forms/reference.md)

[Users Advanced Registration Forms Learn about advanced registration forms, which collect custom profile data over one or more steps during self-service registration. advanced registration formscustom registration](https://fusionauth.io/docs/users/register/advanced-registration-forms.md)

[APIs Create an Email Template API API documentation for the FusionAuth Create an Email Template API. freemarker](https://fusionauth.io/docs/apis/emails/create-an-email-template.md)
---

## Other pages in Advanced Registration Forms

> For the full index of this section, see [Users](https://fusionauth.io/docs/llms-users.txt).

- [Advanced Registration Forms](https://fusionauth.io/docs/users/register/advanced-registration-forms.md): Learn about advanced registration forms, which collect custom profile data over one or more steps during self-service registration.
- [Advanced Registration Form Reference](https://fusionauth.io/docs/users/register/advanced-registration-forms/reference.md): Reference for advanced registration form fields, validation, form rules, consents, localization, and edge cases such as required fields added later.
- [Build an Advanced Registration Form](https://fusionauth.io/docs/users/register/advanced-registration-forms/tutorial.md): Learn how to build a two-step advanced registration form with custom fields, register a user, and read the custom data with the API.
