MyBB Community Forums
Make custom profile field unique - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: 1.8 Support (https://community.mybb.com/forum-175.html)
+--- Forum: General Support (https://community.mybb.com/forum-176.html)
+--- Thread: Make custom profile field unique (/thread-219402.html)



Make custom profile field unique - tvman99 - 2018-08-24

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.


RE: Make custom profile field unique - Wires - 2018-08-24

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?


RE: Make custom profile field unique - effone - 2018-08-24

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.


RE: Make custom profile field unique - tvman99 - 2018-08-24

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.