Revo 2.3.3
I'm using an extended field ("screen name") in member profiles. Naturally I don't want multiple members using the same screen name so I want to know if it's possible to check a submitted [screen] name against the db and if it's a duplicate, prevent it from being saved and also return an error message.
Todd
I assume you mean during signup/registration? If you're using Login.Register for user registration you would write a small snippet that would check through your user list for a given value using the API (modx.getuser) and use it as a pre hook in your register snippet call. Without knowing more about how you're registering/creating your users it's tough to know what the best approach would be.
This would happen after registration, not during.
Once registered the user is directed to their profile page where they can create a public profile, one of the fields is 'screen name'. The 'screen name' is also a required field, if that matters.
Todd
Its the same, a script to check the db to see if a name is taken. Nothing really to do with login.
I have something like that, and one issue is users may just click away from that page. Because they are already registered then the 'required' field is not really required.
When you say "their profile page," I assume you mean a page with the UpdateProfile snippet on it. In that case, I think a preHook snippet could check for duplicates. The snippet should return true if the name is OK, and an error message if it's a duplicate. The duplicate check would be somewhat tricky, especially if there are other extended fields.
Another way to go would be to use JS triggered by the submit button. It could call an Ajax processor that checked for duplicates and if the name wasn't OK, displayed an alert and prevented the form from being submitted.