MyBB Community Forums

Full Version: Make custom profile field unique
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to make some custom profile field unique so that there will be no duplicated ones. Furthermore, This field is only at registration, required and not edible by the user.
Unsure what you're trying to do here. So you don't want users to have the same answer for the custom profile field or am I wrong?
You need to edit member.php, probably at line 260 after CAPTCHA verification. The code roughly should be:

$unique_id = $db->escape_string($mybb->get_input('some_id')); // 'some_id' is form input field name

// target_id is database column name
$query = $db->query("
	SELECT target_id
	FROM ".TABLE_PREFIX."users
	WHERE target_id='{$unique_id}'
");
if($db->num_rows($query) > 0)
{
	$errors[] = "Provided {$some_id} is already in use!"; // $some_id is Field name description (example: 'discord username')
}

Note:
Code not tested but should work.
You need to make sure the desired column in users table exists and the form input field name and database column name are correct.
Even though, profile fields stored in userfields and i fixed query, It doesn't work. I checked and unique_id variable has no value so i think $mybb->get_input is not catching user input. input field name was profile_fields[fid1]

Well, I did it myself. I used core mybb's user array to catch profile field.