Campi utente personalizzati - Verifica del campo

Unsure if I’ve missed it, but the custom User Fields, you can set a field type, bu is their anyway to verify on these fields, such as for a mobile number or via regex so we can verify against any data?

If not currently, could this be added?

2 Mi Piace

There isn’t much point in adding phone number verification. It’s easy for a bad actor to generate a bogus phone number with the right number of digits and highly annoying when a legitimate user has to guess what phone number format someone thinks is the right one.

1 Mi Piace

That was just an example of one field, we have multiple fields to store such as memberships. And it we need some sort of verification that the information is even remotely correct. Currently for a phone number you can enter text.

We should be able to use regex to verify these fields or they are pretty useless.

2 Mi Piace

Also, on the point of mobile numbers, yes they can be fake, but for our use case of the forum, its for their benefit that is correct. And being able to perform some sort of verification means that our scripts that would use them wouldn’t be affected by entering letters instead of numbers for example.

One the second point of different formats, that easy enough where you give the field a description field so you can let them know that. Verification of custom fields is a very basic requirement.

2 Mi Piace

If you want that kind of detail consider an external membership platform and IdM.

This isn’t the kind of thing that discussion software should be doing.

1 Mi Piace

Again, the point isn’t what I want to do with it, but more the fact that custom fields should be able to be verified.

There is no point in them if you can’t somehow verify the data going into them.

How much do you verify the name and identity of your users?

A lot, we’re a closed community. We are only able to verify on email at the moment compared to our current system, but as this can change on both sides, we want them to be able to enter a membership number and mobile and verify on both of those as well. At least if the verification of the field allows us to ensure the info entered is of the right type and length, our scripts using the API can handle the rest.

So you’re not talking about verifying anything, just validating that the data meets an expected format.

Discourse isn’t going to do this for you, you might be able to achieve validation with a plugin, but even then there’s nothing to prevent someone entering bad data in an expected format just to bypass said validation.

Your only real option is to look at something off-site or create a genuine incentive for users to provide real data. Right now you’re fixating on a symptom (not getting the data you want), not the root of the problem (giving users a real and compelling reason to provide it).

Avere una convalida sarebbe incredibilmente utile, soprattutto per i numeri di telefono, che le persone sembrano non riuscire a inserire correttamente con il simbolo + all’inizio. Sì, potremmo semplicemente pulire il database, ma è un vero fastidio.

2 Mi Piace

Non si può essere più d’accordo. Finché puoi verificare i campi in base al formato, alla lunghezza dei caratteri e persino consentendo una regex che un campo deve rispettare, significa che sai di ricevere il tipo di dati corretto, in modo che gli script API possano gestirli senza errori.

Scusate il ritardo con cui arrivo su questo argomento, ma per chiunque stia cercando su Meta per scoprire come validare eventuali campi personalizzati aggiunti, vale la pena menzionare come farlo tramite un plugin.

Nel tuo plugin.rb, utilizza il metodo validate su User. Potrai così esaminare i tuoi campi personalizzati e impostare un errore se alguno non è valido:

require_dependency 'user'

validate User, :my_cool_validation_method do
  field = self.custom_fields['cool_tapes']
  if ! field.blank? && field.include?("bag of four grapes")
    self.errors[:cool_tapes] << "No rhymes allowed."
  end
end

NB: il simbolo :my_cool_validation_method può essere qualsiasi cosa tu voglia, ma deve essere unico nel contesto del modello User.

10 Mi Piace

Potrebbe essere utilizzato per convalidare i campi personalizzati dell’utente durante la registrazione e quando vengono modificati nel profilo utente?

Inoltre, potrebbe essere inserito in qualche modo in un componente del tema?

1 Mi Piace