Unique users, avoid duplicate names
-
Hi Jeff
Since there is no registration, how would we handle duplicated authors names?
At the moment I have came out with generating a unique random string which goes with the name when submitting and asking simple question to users before posting:
Is this you first time?
Yes => Show the field to write your unique name
<p><input id="nameField" name="nome_unico" placeholder="Write your name" class="form-control input-lg usp-input"></p>
No => Display the field where you write your usual name
<input class="form-control input-lg usp-input" id="userName" name="user-submitted-name" type="text" value="" data-required="true" required placeholder="Write your username">
Then with jQuery and php I generate the unique string and I set a live preview of the name and I tell the user to save it somewhere in order to remember the user name generated and use that the next time they post:
var randomString = "<?php //set the random id length $random_id_length = 10; //generate a random id encrypt it and store it in $rnd_id $rnd_id = crypt(uniqid(rand(),1)); //to remove any slashes that might have come $rnd_id = strip_tags(stripslashes($rnd_id)); //Removing any . or / and reversing the string $rnd_id = str_replace(".","",$rnd_id); $rnd_id = strrev(str_replace("/","",$rnd_id)); //finally I take the first 10 characters from the $rnd_id $rnd_id = substr($rnd_id,0,$random_id_length); echo "_$rnd_id" ; ?>"; $('#nameField').on('keyup', function() { var my_value = $(this).val(); $('#userName').val(my_value + codice); $('#userNameMostra').text(my_value + randomString); }); });
In the jQuery we can see 2 things:
1: The script needed to display the name you are typing + the random string
The result would be something like: james_white_3wLCIUWzol
2: I am copying whatever is the genrated unique username to the plugin name field so that it will be send with the form.
The live preview is just so that he has a place where he can see it live as he types and be able to copy it.
Using a unique name makes it possible to do: “Show all posts by this author” as explained here: https://www.ads-software.com/support/topic/display-subcategories.
So this is my solution, am I over complicating it?
How would you approach or what’s your thought in regards of unique author name when they pubblish?Thanks
- The topic ‘Unique users, avoid duplicate names’ is closed to new replies.