Creare e configurare campi utente personalizzati

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

Penso che manchino due immagini sotto queste intestazioni:

Non sono sicuro se sia correlato a Immagini mancanti su Meta.discourse.org – posterò anche lì.

Riesco a vedere quelle immagini? (anche in una finestra anonima)

1 Mi Piace

Non riesco a vederli

Ma il secondo funziona nella mia citazione.

Modifica

1 Mi Piace

È interessante che io possa vedere la seconda immagine nella citazione, ma non nel post originale^^

1 Mi Piace

Hmm. Interessante. Penso che ci sia una correzione in arrivo per il problema Missing images at Meta.discourse.org, quindi spero che venga risolto da quello. :crossed_fingers:

2 Mi Piace

C’è un’impostazione che devo modificare per specificare la lunghezza massima di un campo utente personalizzato? Al momento, in questo campo “Test” che ho creato come campo utente di prova, non riesco a inserire nemmeno un carattere nel mio profilo utente (o anche “Test”, come mostrato).

Mi piacerebbe un tipo di campo: link / URL, è possibile?

PoichĂŠ gli URL sono testo, il campo di testo funziona tecnicamente, @Vaping_Community. Tuttavia, potresti chiedere dettagli aggiuntivi come la convalida del valore o simili.

Potresti cercare o creare un argomento Feature con ciò che hai in mente. :slight_smile:

3 Mi Piace

Ci sono piani per consentire piĂš righe/un compositore per campi utente personalizzati? :folded_hands:

Nota che se vuoi incorporare un link in uno dei campi utente personalizzati, devi usare la sintassi HTML!
<a>href="url">testo del link</a>

Ad esempio, per riconoscere le linee guida/policy della community:

1 Mi Piace

È possibile collegare un’asserzione personalizzata dal mio SSO Auth0 a un campo personalizzato? Attualmente l’utente inserisce le informazioni del campo in Auth0, quindi deve inserirle una seconda volta al momento della registrazione. Vorrei che il valore venisse mappato, se possibile.

È possibile, sÏ:

All’interno del tuo endpoint SSO, hai la possibilità di mappare il claim al payload, ad esempio:

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 Mi Piace

Grazie @dax

C’è un modo per verificare il nome del campo nel db? Ad esempio, abbiamo un campo nome, ho provato custom.firstname, custom.first_name e custom.firstName, nessuno dei quali ha comportato il popolamento dei campi nella schermata di registrazione.

Ho controllato i log degli errori per confermare che i campi token stiano arrivando come mostrato sopra.

Scavando piÚ a fondo nel codice qui, è solo per Discourse Connect SSO? Stiamo usando il plugin Auth0

La sintassi deve essere custom.user_field_x, dove x è l’ID numerico del campo mostrato in /admin/config/user-fields/{x}/edit.

Questa funzionalità di mapping non è disponibile direttamente nel plugin Auth0.

Detto questo, ci sono ancora opzioni per ottenere ciò che stai descrivendo:

  • creare un componente tema. Puoi aggiungere un piccolo script front-end che sincronizzi automaticamente un campo utente personalizzato di Discourse con un valore giĂ  memorizzato in Auth0. Ad esempio, quando un utente accede e il campo è vuoto, lo script può chiamare un endpoint sicuro (una piccola funzione cloud) che recupera il valore del campo da Auth0 e aggiorna il profilo Discourse tramite API.
  • utilizzare strumenti di automazione. Potresti anche utilizzare servizi di automazione esterni come Zapier o Make per eseguire la sincronizzazione al di fuori di Discourse. Il vantaggio è che non devi scrivere/mantenere codice ma paghi solo per il servizio di terze parti.
  • sviluppo personalizzato. Possiamo estendere il plugin Auth0 stesso per supportare nativamente il mapping di claim personalizzati nei campi utente all’accesso, o creare un plugin personalizzato che lavori in coppia con il plugin Auth0.

Uno svantaggio evidente dell’approccio del componente tema è che dovresti scrivere e mantenere tu stesso codice personalizzato, prestando attenzione anche alla sicurezza per evitare di introdurre potenziali bug o vulnerabilità. Onestamente, non è una soluzione che consiglierei per un sito di produzione come il tuo.

Se fossi nella tua posizione, propenderei più per la seconda opzione, utilizzando strumenti di terze parti, o prenderei in considerazione l’invio di una richiesta di funzionalità o di una richiesta di lavoro personalizzato (a seconda della valutazione dei nostri project manager) per migliorare il plugin Auth0 stesso.

Se sei interessato a esplorare quest’ultima opzione, possiamo continuare la discussione privatamente.

1 Mi Piace