创建和配置自定义用户字段

:bookmark: 本指南介绍如何在 Discourse 中创建和配置自定义用户字段,包括如何将其添加到注册表单、用户个人资料以及用户目录中。

:person_raising_hand: 所需用户权限:管理员

自定义用户字段允许您收集除标准个人资料字段之外的额外用户信息。这些字段可以显示在用户卡片、用户摘要页面上,甚至可以通过数据浏览器(Data Explorer)插件进行检索。本指南将引导您完成创建和配置自定义用户字段的过程。

添加用户字段

  1. 前往 管理员 > 社区 > 用户字段 (discourse.example.com/admin/config/user-fields)。

  2. 如果您尚未创建任何用户字段,您将看到以下屏幕:

  3. 点击“添加用户字段”按钮以添加新字段。

选择字段类型

字段类型决定了用户在注册表单上看到的输入框类型。请根据您要收集的信息类型进行选择:

文本字段

  • 适用于可能有很多答案的简短问题(例如,“你在哪家公司工作?”)
  • 显示为单行 HTML 文本输入框

多行文本

  • 适用于可能需要较长、多行答案的问题(例如,“介绍一下你自己”)
  • 显示为多行 HTML 文本域输入框

日期

  • 用于收集日期值(例如,“你的出生日期是什么时候?”)
  • 显示为日期选择器输入框

确认

  • 用于是/否问题(例如,“您想订阅我们的通讯吗?”)
  • 显示为 HTML 复选框
  • 使用 HTML 添加用户需要确认的重要链接,例如:
    我同意阅读并遵守 <a href="https://meta.discourse.org/guidelines">社区准则</a>。

下拉菜单

要为下拉菜单字段添加选项:

  1. 点击选项输入框
  2. 输入答案并点击“创建”
  3. 对额外选项重复此操作

完成的选项应类似于这样:

多选

  • 用于用户可以从一组选项中选择多个答案的问题(例如,“哪些话题感兴趣?”)
  • 显示为多选输入框
  • 选项的配置方式与下拉菜单字段相同

设置字段名称和描述

  • 字段名称:显示在注册表单和用户个人资料中输入框之前
  • 字段描述:显示在输入框之后,以帮助用户填写该字段

:information_source: 保存字段时,字段名称和描述均为必填项。

以下是自定义字段在注册表单上的显示效果:

配置用户字段选项

字段要求

  • 可选 - 用户可以选择留空可选字段
  • 所有用户 - 当字段对所有用户为必填时,每个账户(包括已登录用户)都将强制填写。这对于服务条款(ToS)要求等场景非常有用。
  • 注册时 - 所有新账户都必须填写该字段。

此外,在创建表单的底部,您会找到以下偏好复选框:

  • 注册后可编辑:允许用户从他们的个人资料页面更新该字段
  • 在公开个人资料中显示:在用户的摘要页面上显示字段值
  • 在用户卡片中显示:在用户卡片上显示字段值
  • 可搜索:启用基于此字段值在用户目录中搜索用户的功能
  • 在注册表单中显示:控制字段是否显示在注册表单上。当字段要求为“所有用户”或“注册时”,或者字段在注册后不可编辑时,此项会自动启用(且无法禁用)。

在公开个人资料中显示

启用后,字段值将显示在用户的个人资料页面上:

在用户卡片中显示

启用后,字段值将显示在用户卡片上:

可搜索

启用后,您可以根据用户的自定义字段值搜索用户:

保存和编辑字段

  1. 点击“保存”以将该字段添加到您网站的用户字段列表中
  2. 要编辑字段,请点击列表中该字段旁边的“编辑”按钮
  3. 要删除字段,请点击该字段旁边的省略号菜单(⋮)并选择“删除”

将自定义字段添加到用户目录

  1. 前往用户目录
  2. 点击扳手图标:

  1. 勾选您想要显示的自定义用户字段
  2. 点击“保存”

选定的自定义字段现在将出现在用户目录表格中:

40 个赞
Any Plugins/Easy Mods for an Extended User Profile
Add introductory text for sign-up
Setting Security Parameters: Log-In, Read-Only, Protected Groups
Theme-Component v Plugin: What's the difference
User preference on theme components
Users self-select Category on Registration... is it possible?
Private custom user fields...?
Can we implement a system for user remarks during registration for admin review?
User customizable theme components (how-to)
This freaking software works so well I can’t even
User Field Prompt
New user reviews: admin assignment and logging of progress
Add users to groups on signup
How to add min or max values in custom fields?
Add a custom per-user setting in a plugin
Welcome questions on the first screen for bio
Announcing - Gender Pronouns Userfield on Meta
Grant Custom Badge Upon Reading ToS
If topic info is too long, tags are cut off and create a blank line
Required vs. optional sign-up fields
Terms of Service Checkbox
Hidden User Fields
New user filter by custom field and contact
Social Features
Where in Discourse can users publicly share PII?
Linking "static" information about member to topic posted
Add custom fields to signup and login
Using Discourse as a social media platform
Add users to groups through custom field automation
Custom user post display
Disable account confirm emails when creating users via API
Links in additional fields
Clickable Social Icon Links on Profile
Extend Existing Controller?
Requiring acceptance of terms and conditions
"Fake" OAuth Provider?
Extend Existing Controller?
Allow users to block keywords
Customize Your Site Branding
Restrict the users to post in the groups who haven't uploaded their profile picture
Adding non-visible user custom fields to the API
Seeking Advice: making a discourse forum hyper local
Can add short message to verify? Just input phone number can sign up
Add terms when make new topic
Export custom field for users in discourse hosted forum
Customizing Sign-up and Log in
Grouping poll results by user custom field
Disclaimer for tutorials
How to add custom logic input on the signup page?
Terms of service changes in Discourse platform
Custom user fields not available in api