Hi Guys,
I'm trying to build a nice registration form where users receive a unique (autoincrement) username. Something like:
t000001
t000002
etc..
I use the pre-populate feature and have the following code in my functions.php
<?php
function populate_lidnummer($value){
global $wpdb;
$usernames = $wpdb->get_results("SELECT ID, user_url FROM $wpdb->users ORDER BY ID DESC LIMIT 1");
foreach ($usernames as $username) {
$lastuser = $username->ID;
$newuser_temp = $lastuser + 1;
$num = strlen($newuser_temp);
$max = 5;
$zeros = $max - $num;
return 't' . $newuser2 = str_repeat("0",$zeros)."".$newuser_temp;;
}
}?>
This is not ideal because when several people filling out the form there is a problem with the uniqueness of the username.
Now i thought it might be easier to populate the field just before the users hitting the submit button on the registration page. So the most recent data is populated from the database.
How can i do this?