Somewhat related to a previous thread: Update existing person documents
The generate_shortcode_on_contacts transition’ does allow you to automatically assign a unique code for each contact. However, at this point there is no way to customize the format of that id code (e.g. if you needed it to be related to the 3 first letters of the place, etc). Outside of this transition, though, it is not going to be possible to guarantee uniqueness of a value generated in a form. The user submitting the form probably does not even have access to check all the relevant docs for uniqueness.
Thinking outside the box a bit, if you were willing to accept a certain probability of uniqueness (proportional to the length of the id code, itself) then it would probably be pretty easy to write a custom extension-lib that could generate id codes of whatever shape you need using something like the uuid package or even just Math.random. This extension could then be used within a form and could even except data from the form as input (e.g. the place names). However, as noted before, there would be no way for offline logic like this to absolutely guarantee that it will avoid collisions.