turn username into a profile link
foxxie Offline
Junior Member
**
Posts: 9
Joined: Feb 2017
Post: #1
turn username into a profile link
Hello!

I've searched for quite a while but didn't find anything that fits.
I'm using xthreads for different thread descriptions. [My forum is used for a rpg and the fields are for date, time, location of the scene.] Now I would like to add another field for the character names of the attending characters/users. Is there a way the user can put two and more usernames into a field (only one field, the names most likely seperated by comma or something) and those names turn into a normal link that redirects to the profile like with any other username in the forum?
Thanks in advance.
02-08-2017 07:57 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #2
RE: turn username into a profile link
Do you mean by the usernames/character names are the forum users username?

02-09-2017 03:08 AM
Find all posts by this user Quote this message in a reply
foxxie Offline
Junior Member
**
Posts: 9
Joined: Feb 2017
Post: #3
RE: turn username into a profile link
Yes! Each character has its own account.
02-09-2017 05:19 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #4
RE: turn username into a profile link
XThreads itself supports multiple values (comma separated for textbox and new line for textarea).
The problem is validating whether the username(s) entered by the user is a valid username or not, including whether they are duplicate or not (for example: User 1, User 2, User 1).
If you store the username inside the custom field, it won't be updated automatically if the user decides to change the usernames (character names).
So, you need an additional plugin for that.
The alternative way is store the uid(s) rather than the username(s). But still, you still need the validation and an additional plugin to load the usernames based on the uid to turn them into a profile link.

02-09-2017 11:54 PM
Find all posts by this user Quote this message in a reply
foxxie Offline
Junior Member
**
Posts: 9
Joined: Feb 2017
Post: #5
RE: turn username into a profile link
Hm. Okay, so there would be a lot of additional work. Since I have only little knowledge when it comes to coding, I'll stick with a field only for the names without turning them into a link. But thank you for your thoughts about it!
02-10-2017 12:45 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #6
RE: turn username into a profile link
To make it a bit "better", you can try using the select2.js included by MyBB.

02-14-2017 12:16 AM
Find all posts by this user Quote this message in a reply
foxxie Offline
Junior Member
**
Posts: 9
Joined: Feb 2017
Post: #7
RE: turn username into a profile link
Is that the script used in PMs to find a username? If so, how could I use it?
[Sorry, I'm really just a beginner. Frown]
02-14-2017 10:26 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #8
RE: turn username into a profile link
Yep. The script used when sending PM.
The js could be found inside private_send_autocomplete template.
You need to modify it (especially for the ID of the input), and add an ID to your custom field.

Here is a simple example for that (assuming the field is a textbox):
Edit the field:
Allow multiple values for this field: Yes
Use Custom Input HTML: Yes
Input Field HTML:

HTML Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<input type="text" id="xtun" class="textbox"{NAME_PROP}{MAXLEN_PROP}{WIDTH_PROP_SIZE}{TABINDEX_PROP}{REQUIRED_PROP} value="{VALUE}" style="min-width: 300px;" />
<link rel="stylesheet" href="{$mybb->asset_url}/jscripts/select2/select2.css?ver=1806">
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/select2/select2.min.js?ver=1806"></script>
<script type="text/javascript">
<!--
if(use_xmlhttprequest == "1")
{
	MyBB.select2();
	$("#xtun").select2({
		placeholder: "Username(s), separated by comma. Maximum 3 users.",
		minimumInputLength: 3,
		maximumSelectionSize: 3,
		multiple: true,
		ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
			url: "xmlhttp.php?action=get_users",
			dataType: 'json',
			data: function (term, page) {
				return {
					query: term, // search term
				};
			},
			results: function (data, page) { // parse the results into the format expected by Select2.
				// since we are using custom formatting functions we do not need to alter remote JSON data
				return {results: data};
			}
		},
		initSelection: function(element, callback) {
			var query = $(element).val();
			if (query !== "") {
				var newqueries = [];
				exp_queries = query.split(",");
				$.each(exp_queries, function(index, value ){
					if(value.replace(/\s/g, '') != "")
					{
						var newquery = {
							id: value.replace(/,\s?/g, ", "),
							text: value.replace(/,\s?/g, ", ")
						};
						newqueries.push(newquery);
					}
				});
				callback(newqueries);
			}
		}
	});
}
// -->
</script>

* the above code based on 1.8.6. I don't have MyBB version above 1.8.6. So maybe you need to modify it a bit.

Multiple Value Delimiter: ,

Change the maximumSelectionSize if you are allowing more than 3 usernames.


02-15-2017 03:07 AM
Find all posts by this user Quote this message in a reply
foxxie Offline
Junior Member
**
Posts: 9
Joined: Feb 2017
Post: #9
RE: turn username into a profile link
Thank you!

So I tried to add a field for that in my test forum. For the moment with just the copied code of the private_send_autocomplete templated. I wanted to modify it afterwards so that I already have it if something goes wrong (what most likely will happen). But the first misstep came quicker than thought: I can't save the field. ^^

That's (so far) the code I wanted to put into the field you said:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<link rel="stylesheet" href="{$mybb->asset_url}/jscripts/select2/select2.css?ver=1807">
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/select2/select2.min.js?ver=1806"></script>
<script type="text/javascript">
<!--
if(use_xmlhttprequest == "1")
{
	MyBB.select2();
	$("#to").select2({
		placeholder: "{$lang->search_user}",
		minimumInputLength: 2,
		maximumSelectionSize: 8,
		multiple: true,
		ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
			url: "xmlhttp.php?action=get_users",
			dataType: 'json',
			data: function (term, page) {
				return {
					query: term, // search term
				};
			},
			results: function (data, page) { // parse the results into the format expected by Select2.
				// since we are using custom formatting functions we do not need to alter remote JSON data
				return {results: data};
			}
		},
		initSelection: function(element, callback) {
			var query = $(element).val();
			if (query !== "") {
				var newqueries = [];
				exp_queries = query.split(",");
				$.each(exp_queries, function(index, value ){
					if(value.replace(/\s/g, '') != "")
					{
						var newquery = {
							id: value.replace(/,\s?/g, ", "),
							text: value.replace(/,\s?/g, ", ")
						};
						newqueries.push(newquery);
					}
				});
				callback(newqueries);
			}
		}
	});

  $("#bcc").select2({
		placeholder: "{$lang->search_user}",
		minimumInputLength: 2,
		maximumSelectionSize: {$mybb->usergroup['maxpmrecipients']},
		multiple: true,
		ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
			url: "xmlhttp.php?action=get_users",
			dataType: 'json',
			data: function (term, page) {
				return {
					query: term, // search term
				};
			},
			results: function (data, page) { // parse the results into the format expected by Select2.
				// since we are using custom formatting functions we do not need to alter remote JSON data
				return {results: data};
			}
		},
		initSelection: function(element, callback) {
			var query = $(element).val();
			if (query !== "") {
				var newqueries = [];
				exp_queries = query.split(",");
				$.each(exp_queries, function(index, value ){
					if(value.replace(/\s/g, '') != "")
					{
						var newquery = {
							id: value.replace(/,\s?/g, ", "),
							text: value.replace(/,\s?/g, ", ")
						};
						newqueries.push(newquery);
					}
				});
				callback(newqueries);
			}
		}
	});
}
// -->
</script>


I'll get this error:

Quote:No multiple value delimiter defined (tip, you can set this to be a space).

I think I know where the problem is - is it the input formatter? By default there stands {VALUE}. What do I have to change?

Another question. Which ID do you mean? Do I have to put the one of the field into the script or the css-id like in the first row of the code?
02-15-2017 05:52 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #10
RE: turn username into a profile link
(02-15-2017 05:52 AM)foxxie Wrote:  I'll get this error:
Quote:No multiple value delimiter defined (tip, you can set this to be a space).

I think I know where the problem is - is it the input formatter? By default there stands {VALUE}. What do I have to change?

(02-15-2017 03:07 AM)RateU Wrote:  Multiple Value Delimiter: ,

(02-15-2017 05:52 AM)foxxie Wrote:  Another question. Which ID do you mean? Do I have to put the one of the field into the script or the css-id like in the first row of the code?

(02-15-2017 03:07 AM)RateU Wrote:  

HTML Code
<input type="text" id="xtun" class="textbox"{NAME_PROP}{MAXLEN_PROP}{WIDTH_PROP_SIZE}{TABINDEX_PROP}{REQUIRED_PROP} value="{VALUE}" style="min-width: 300px;" />



(02-15-2017 05:52 AM)foxxie Wrote:  That's (so far) the code I wanted to put into the field you said:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<link rel="stylesheet" href="{$mybb->asset_url}/jscripts/select2/select2.css?ver=1807">
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/select2/select2.min.js?ver=1806"></script>
<script type="text/javascript">
<!--
if(use_xmlhttprequest == "1")
{
	MyBB.select2();
	$("#to").select2({
		placeholder: "{$lang->search_user}",
		minimumInputLength: 2,
		maximumSelectionSize: 8,
		multiple: true,
		ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
			url: "xmlhttp.php?action=get_users",
			dataType: 'json',
			data: function (term, page) {
				return {
					query: term, // search term
				};
			},
			results: function (data, page) { // parse the results into the format expected by Select2.
				// since we are using custom formatting functions we do not need to alter remote JSON data
				return {results: data};
			}
		},
		initSelection: function(element, callback) {
			var query = $(element).val();
			if (query !== "") {
				var newqueries = [];
				exp_queries = query.split(",");
				$.each(exp_queries, function(index, value ){
					if(value.replace(/\s/g, '') != "")
					{
						var newquery = {
							id: value.replace(/,\s?/g, ", "),
							text: value.replace(/,\s?/g, ", ")
						};
						newqueries.push(newquery);
					}
				});
				callback(newqueries);
			}
		}
	});

  $("#bcc").select2({
		placeholder: "{$lang->search_user}",
		minimumInputLength: 2,
		maximumSelectionSize: {$mybb->usergroup['maxpmrecipients']},
		multiple: true,
		ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
			url: "xmlhttp.php?action=get_users",
			dataType: 'json',
			data: function (term, page) {
				return {
					query: term, // search term
				};
			},
			results: function (data, page) { // parse the results into the format expected by Select2.
				// since we are using custom formatting functions we do not need to alter remote JSON data
				return {results: data};
			}
		},
		initSelection: function(element, callback) {
			var query = $(element).val();
			if (query !== "") {
				var newqueries = [];
				exp_queries = query.split(",");
				$.each(exp_queries, function(index, value ){
					if(value.replace(/\s/g, '') != "")
					{
						var newquery = {
							id: value.replace(/,\s?/g, ", "),
							text: value.replace(/,\s?/g, ", ")
						};
						newqueries.push(newquery);
					}
				});
				callback(newqueries);
			}
		}
	});
}
// -->
</script>



(02-15-2017 03:07 AM)RateU Wrote:  Input Field HTML:

HTML Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<input type="text" id="xtun" class="textbox"{NAME_PROP}{MAXLEN_PROP}{WIDTH_PROP_SIZE}{TABINDEX_PROP}{REQUIRED_PROP} value="{VALUE}" style="min-width: 300px;" />
<link rel="stylesheet" href="{$mybb->asset_url}/jscripts/select2/select2.css?ver=1806">
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/select2/select2.min.js?ver=1806"></script>
<script type="text/javascript">
<!--
if(use_xmlhttprequest == "1")
{
	MyBB.select2();
	$("#xtun").select2({
		placeholder: "Username(s), separated by comma. Maximum 3 users.",
		minimumInputLength: 3,
		maximumSelectionSize: 3,
		multiple: true,
		ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
			url: "xmlhttp.php?action=get_users",
			dataType: 'json',
			data: function (term, page) {
				return {
					query: term, // search term
				};
			},
			results: function (data, page) { // parse the results into the format expected by Select2.
				// since we are using custom formatting functions we do not need to alter remote JSON data
				return {results: data};
			}
		},
		initSelection: function(element, callback) {
			var query = $(element).val();
			if (query !== "") {
				var newqueries = [];
				exp_queries = query.split(",");
				$.each(exp_queries, function(index, value ){
					if(value.replace(/\s/g, '') != "")
					{
						var newquery = {
							id: value.replace(/,\s?/g, ", "),
							text: value.replace(/,\s?/g, ", ")
						};
						newqueries.push(newquery);
					}
				});
				callback(newqueries);
			}
		}
	});
}
// -->
</script>


02-16-2017 02:56 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: