إنشاء وتكوين حقول مستخدم مخصصة

: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:

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

أعتقد أن هناك صورتين مفقودتين تحت هذه العناوين:

لست متأكدًا مما إذا كان الأمر يتعلق بـ صور مفقودة في Meta.discourse.org - سأنشر هناك أيضًا.

هل يمكنني رؤية تلك الصور؟ (أيضًا في نافذة مجهولة)

إعجاب واحد (1)

لا يمكنني رؤية هؤلاء

لكن الثاني يعمل في اقتباسي.

تعديل

إعجاب واحد (1)

من المثير للاهتمام أنني أستطيع رؤية الصورة الثانية في الاقتباس، ولكن ليس في المنشور الأصلي^^

إعجاب واحد (1)

هممم. هذا مثير للاهتمام. أعتقد أن هناك إصلاحًا قادمًا لمشكلة Missing images at Meta.discourse.org ، لذا نأمل أن يتم حلها بحلول ذلك الوقت. :crossed_fingers:

إعجابَين (2)

هل هناك إعداد يجب تعديله لتحديد الحد الأقصى لطول حقل مستخدم مخصص؟ حاليًا، في حقل “Test” هذا الذي أنشأته كحقل مستخدم اختباري، لا يمكنني إدخال حرف واحد في ملف تعريف المستخدم الخاص بي (أو حتى “Test”، كما هو موضح).

أود حقل من نوع: رابط / عنوان URL، هل هذا ممكن؟

بما أن عناوين URL هي نصوص، فإن حقل النص يعمل تقنيًا، @Vaping_Community. ومع ذلك، قد تكون تطلب تفاصيل إضافية مثل التحقق من القيمة أو ما شابه ذلك.

قد تبحث عن موضوع Feature أو تنشئه بما تفكر فيه. :slight_smile:

3 إعجابات

هل هناك أي خطط للسماح بأسطر متعددة/محرر لحقول المستخدم المخصصة؟ :folded_hands:

لاحظ أنه إذا كنت ترغب في تضمين رابط في أحد حقول المستخدم المخصصة، فيجب عليك استخدام صيغة HTML!
<a>رابط</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...]
3 إعجابات

شكراً @dax

هل هناك طريقة للتحقق من اسم الحقل في قاعدة البيانات؟ على سبيل المثال، لدينا حقل الاسم الأول، جربت custom.firstname و custom.first_name و custom.firstName، ولم يؤدِ أي منها إلى ملء الحقول في شاشة التسجيل.

لقد تحققت من سجلات الأخطاء للتأكد من أن حقول الرمز المميز تأتي كما هو موضح أعلاه.

بالتعمق أكثر في الكود هنا، هل هذا فقط لـ Discourse Connect SSO؟ نحن نستخدم إضافة Auth0

يجب أن يكون بناء الجملة custom.user_field_x، حيث x هو معرف الحقل الرقمي المعروض في /admin/config/user-fields/{x}/edit.

ميزة التعيين هذه غير متوفرة في إضافة Auth0 مباشرة.

ومع ذلك، لا تزال هناك خيارات لتحقيق ما تصفه:

  • إنشاء مكون سمة. يمكنك إضافة نص برمجي صغير للواجهة الأمامية يقوم تلقائيًا بمزامنة حقل مستخدم مخصص في Discourse مع قيمة مخزنة بالفعل في Auth0. على سبيل المثال، عند تسجيل دخول المستخدم وكان الحقل فارغًا، يمكن للنص البرمجي استدعاء نقطة نهاية آمنة (وظيفة سحابية صغيرة) تجلب قيمة الحقل من Auth0 وتحدث ملف تعريف Discourse عبر واجهة برمجة التطبيقات (API).
  • استخدام أدوات الأتمتة. يمكنك أيضًا استخدام خدمات الأتمتة الخارجية مثل Zapier أو Make لأداء هذه المزامنة خارج Discourse. الميزة هي أنك لا تحتاج إلى كتابة/صيانة التعليمات البرمجية ولكنك تدفع فقط مقابل خدمة الطرف الثالث.
  • تطوير مخصص. يمكننا توسيع إضافة Auth0 نفسها لدعم تعيين المطالبات المخصصة في حقول المستخدم عند تسجيل الدخول بشكل أصلي، أو بناء إضافة مخصصة تعمل بالتوازي مع إضافة Auth0.

العيب الواضح لنهج مكون السمة هو أنك ستحتاج إلى كتابة وصيانة التعليمات البرمجية المخصصة بنفسك، مع توخي الحذر أيضًا من الناحية الأمنية لتجنب إدخال أخطاء أو ثغرات محتملة. بصراحة، هذا ليس حلاً أوصي به لموقع إنتاجي مثل موقعك.

لو كنت مكانك، لفضلت الخيار الثاني، باستخدام أدوات الطرف الثالث، أو النظر في تقديم طلب ميزة أو طلب عمل مخصص (اعتمادًا على تقييم مديري المشاريع لدينا) لتعزيز إضافة Auth0 نفسها.

إذا كنت مهتمًا باستكشاف الخيار الأخير، يمكننا مواصلة المناقشة بشكل خاص.

إعجاب واحد (1)