カスタムユーザーフィールドの作成と設定

:bookmark: This guide explains how to create and configure custom user fields in Discourse, including how to add them to the signup form, user profiles, and user directory.

:person_raising_hand: Required user level: Administrator

Custom user fields allow you to collect additional information from your users beyond the standard profile fields. These fields can be displayed on user cards, user summary pages, and even retrieved using the Data Explorer plugin. This guide will walk you through the process of creating and configuring custom user fields.

Adding a user field

  1. Go to Admin > Community > User Fields (discourse.example.com/admin/config/user-fields).

  2. If you haven’t created any user fields yet, you’ll see this screen:

  3. Click the “Add user field” button to add a new field.

Choosing a field type

The field type determines the input field users will see on the signup form. Choose based on the kind of information you’re collecting:

Text field

Confirmation

Dropdown

To add options for a dropdown field:

  1. Click on the option input
  2. Type an answer and click “Create”
  3. Repeat for additional options

The completed options should look similar to this:

Setting the field name and description

  • Field Name: Appears before the input on the signup form and user profile
  • Field Description: Appears after the input to help users complete the field

:information_source: Both the field name and description are required to save a field.

Here’s how custom fields appear on the signup form:

Configuring user field options

Field Requirements

  • Optional - Optional fields may be left empty by users
  • For all users - When a field is required by all users, every account, including logged on users will be forced to fill it. This is very useful for cases such as a terms-of-service (ToS) requirement.
  • On signup - All new account will be required to fill the field.

Additionally, at the bottom of the creation form, you’ll find these options:

  • Editable after signup: Allows users to update the field from their profile page
  • Required at signup: Makes the field mandatory during account creation
  • Show on public profile: Displays the field value on the user’s summary page
  • Show on user card: Shows the field value on the user card
  • Searchable: Enables searching for users based on this field’s value in the user directory

Show on public profile

When enabled, the field value will be shown on the user’s profile page:

Show on user card

When enabled, the field value will be displayed on the user card:

Searchable

When enabled, you can search for users based on their custom field values:

Saving and editing fields

  1. Click “Save” to add the field to your site’s list of user fields
  2. To edit a field, click the “Edit” button next to it in the list
  3. To delete a field, click the “Delete” button

Adding custom fields to the user directory

  1. Go to the user directory
  2. Click the wrench icon:

  1. Check the custom user fields you want to display
  2. Click “Save”

The selected custom fields will now appear in the user directory table:

Last edited by @fzngagan 2025-07-17T09:12:38Z

Last checked by @hugh 2024-08-27T04:45:20Z

Check documentPerform check on document:
「いいね!」 38

これらの見出しの下に画像が2つ不足していると思います。

Meta.discourse.orgの画像欠落についてに関連しているか分かりませんが、そちらにも投稿します。

これらの画像が見えますか?(匿名ウィンドウでも)

「いいね!」 1

それらが見えません

しかし、私の引用では2番目のものが機能します。

編集

「いいね!」 1

引用では2枚目の画像が見えますが、元の投稿では見えません^^

「いいね!」 1

なるほど。それは興味深いですね。Missing images at Meta.discourse.org の問題に対する修正が来ると思うので、それで解決されるといいですね。:crossed_fingers:

「いいね!」 2

カスタムユーザーフィールドの最大長を指定するために変更する必要がある設定はありますか?現在、テスト用のユーザーフィールドとして作成したこの「テスト」フィールドでは、ユーザープロファイルに1文字も入力できません(表示されているように「テスト」さえも)。

リンク/URLフィールドタイプは可能ですか?

URLはテキストなので、textフィールドは技術的には機能します。@Vaping_Community。ただし、値の検証などの追加の詳細を求めているのかもしれません。

お考えの機能について、Feature トピックを検索または作成することもできます。:slight_smile:

「いいね!」 3

カスタムユーザーフィールドで複数行/コンポーザーを使用する予定はありますか?:folded_hands:

カスタムユーザーフィールドにリンクを埋め込みたい場合は、HTML構文を使用する必要があります!
<a href="url">リンクテキスト</a>

たとえば、コミュニティガイドライン/ポリシーを承認するには:

「いいね!」 1

Auth0 SSO のカスタムクレームをカスタムフィールドに連携することはできますか?現在、ユーザーは Auth0 でフィールド情報を入力してから、サインアップ時に再度入力する必要があります。可能であれば、値をマッピングしたいと思います。

はい、可能です。

SSOエンドポイント内で、クレームをペイロードにマッピングする機能があります。例:

const ssoPayload = {
  nonce: nonce,
  email: user.email,
  external_id: user.sub,
  username: user.nickname,
  name: user.name,
  add_groups: a_custom_group,
  'custom.user_field_1': user['https://yourdomain.com/company_id'],
  'custom.user_field_2':  [etc...]
「いいね!」 2

@daxさん、ありがとうございます。

DBでフィールド名を確認する方法はありますか?例えば、名(first name)フィールドがありますが、custom.firstnamecustom.first_namecustom.firstNameを試しましたが、サインアップ画面でフィールドが入力されませんでした。

エラーログを確認し、トークンフィールドが上記のように表示されていることを確認しました。

さらにコードを詳しく見ていますが、これはDiscourse Connect SSO専用ですか?Auth0プラグインを使用しています。

構文は custom.user_field_x である必要があります。ここで x/admin/config/user-fields/{x}/edit に表示される数値フィールド ID です。

そのマッピング機能はAuth0プラグインでは直接利用できません。

とはいえ、説明されていることを実現するためのオプションはまだあります。

  • テーマコンポーネントの作成。DiscourseのカスタムユーザーフィールドをAuth0に既に保存されている値と自動的に同期する小さなフロントエンドスクリプトを追加できます。たとえば、ユーザーがログインしたときにフィールドが空の場合、スクリプトはセキュアなエンドポイント(小さなクラウド関数)を呼び出して、Auth0からフィールド値を取得し、API経由でDiscourseプロファイルを更新できます。
  • 自動化ツールの使用。ZapierやMakeなどの外部自動化サービスを使用して、Discourse外で同期を実行することもできます。利点は、コードの作成/保守を行う必要がなく、サードパーティサービスの料金を支払うだけで済むことです。
  • カスタム開発。Auth0プラグイン自体を拡張して、ログイン時にカスタムクレームをユーザーフィールドにネイティブにマッピングできるようにしたり、Auth0プラグインと連携するカスタムプラグインを構築したりできます。

テーマコンポーネントアプローチの明確な欠点は、カスタムコードを自分で作成および保守する必要があり、潜在的なバグや脆弱性を回避するためにセキュリティの観点からも注意が必要なことです。正直なところ、あなたの本番サイトのようなサイトにはお勧めできないソリューションです。

もし私があなたの立場なら、2番目のオプション(サードパーティツールの使用)に傾くか、Auth0プラグイン自体の強化のために機能リクエストまたはカスタムワークリクエスト(プロジェクトマネージャーの評価による)を提出することを検討します。

最後のオプションを検討することに興味がある場合は、プライベートで議論を続けることができます。

「いいね!」 1